package stego;

import StegoGUI.JPanel_AddCarrierImagePath_OR_UploadDestination;
import StegoGUI.StegoFileSelection;
import java.awt.Color;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class Drivers
{

    private static String strMyClassName = "Drivers.java";
    public static final int maxEmbedContentSize = 6000;
    public static final int maxBatchIdentifierSize = 4;
    public static final int maxCurrIndexSize = 2;
    public static final int maxOf_CurrIndexSize = 2;
    public static final int maxNumFileExtensionIndexTypeChars = 2;
    public static final int maxNumFileExtensionChars = 4;
    public static final String FRAGMENT_DELIMETER = "_";
    public static final int maxNumOfCarrierFilePaths = 100;
    public static final String strAnalyzedCarrierImageFolderName = "Analyzed";
    public static final int numOfOverheadBytes = (new String("6000")).length() + 4 + 2 + 2 + 2 + 4;
    public static boolean allEmbed_OR_Extract_ContentSizeEntered = false;
    String arrCarrierMessageExtension[] = {
        "exe", "txt", "jpg"
    };
    public static String acceptableFileExtensionsForStego[] = {
        "UKN", "txt", "tiff", "tif", "bmp", "mp3", "wma", "mp4", "m4p", "avi"
    };
    public static java.util.List lstAcceptableFileExtensionsForStego;
    public static String specialFormats_jpgPngGif[] = {
        "JPEG", "JPG", "PNG", "GIF"
    };
    public static java.util.List lstSpecialFormats_jpgPngGif;
    public static String strExpectedName_EncryptionKey_PUBLIC = "public.key";
    public static String strExpectedName_EncryptionKey_PRIVATE = "private.key";
    public static final int UPLOAD_DOWNLOAD_CONTENT_TAB_PANE_INDEX = 4;
    public static String strJarFileNotFound = "No JAR Files found under Top Folder";
    public static Color clrBackground = new Color(240, 240, 240);
    public static boolean displayedInitialFileChooserError = false;

    public Drivers()
    {
    }

    public static String formatBinString(String strToFormat)
    {
        for(int i = 0; strToFormat.length() < 8; i++)
        {
            strToFormat = (new StringBuilder("0")).append(strToFormat).toString();
        }

        return strToFormat;
    }

    public static boolean appendTextToInteractionContent_TextPane(String strToAppend, boolean insertCarriageReturnAtEndOfString)
    {
        try
        {
            appendTextToJTextPane(StegoFileSelection.jtxtpneInteractionContent, strToAppend, insertCarriageReturnAtEndOfString);
        }
        catch(Exception e)
        {
            eop("appendTextToInteractionContent_TextPane", strToAppend, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static boolean appendTextToJTextPane(JTextPane jtxtPneToAppend, String strToAppend, boolean insertCarriageReturnAtEndOfString)
    {
        try
        {
            if(insertCarriageReturnAtEndOfString)
            {
                strToAppend = (new StringBuilder(String.valueOf(strToAppend))).append("\n").toString();
            }
            StyledDocument doc = jtxtPneToAppend.getStyledDocument();
            SimpleAttributeSet attribute = new SimpleAttributeSet();
            StyleConstants.setForeground(attribute, Color.black);
            StyleConstants.setBackground(attribute, Color.white);
            StyleConstants.setBold(attribute, false);
            doc.insertString(doc.getLength(), strToAppend, attribute);
        }
        catch(Exception e)
        {
            eop("appendTextToJTextPane", strToAppend, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static boolean setTextToJTextPane(JTextPane jtxtPneToAppend, String strToAppend)
    {
        try
        {
            StyledDocument doc = jtxtPneToAppend.getStyledDocument();
            SimpleAttributeSet attribute = new SimpleAttributeSet();
            StyleConstants.setForeground(attribute, Color.black);
            StyleConstants.setBackground(attribute, Color.white);
            StyleConstants.setBold(attribute, false);
            jtxtPneToAppend.setText("");
            doc.insertString(0, strToAppend, attribute);
        }
        catch(Exception e)
        {
            eop("setTextToJTextPane", strToAppend, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static int getFileExtensionType(File fleToProcess)
    {
        int returnType;
        returnType = lstAcceptableFileExtensionsForStego.indexOf(getFileExtension(fleToProcess, true));
        if(returnType < 0)
        {
            returnType = 0;
        }
        return returnType;
        Exception e;
        e;
        eop("getFileExtensionType", strMyClassName, e, " File was prolly null", true);
        return 0;
    }

    public static void jop_Error(String strMsg, String strTitle)
    {
        JOptionPane.showMessageDialog(null, strMsg, strTitle, 0);
    }

    public static void jop_Warning(String strMsg, String strTitle)
    {
        JOptionPane.showMessageDialog(null, strMsg, strTitle, 2);
    }

    public static void jop_Message(String strMsg, String strTitle)
    {
        JOptionPane.showMessageDialog(null, strMsg, strTitle, 1);
    }

    public static void jop_Message(String strMsg)
    {
        JOptionPane.showMessageDialog(null, strMsg, "Message", 1);
    }

    public static String jop_Input(String strMsg, String strTitle, boolean recallIfInvalidInput)
    {
        String text = JOptionPane.showInputDialog(null, strMsg, strTitle, 3);
        if(recallIfInvalidInput && text != null && text.length() != 4)
        {
            return jop_Input(strMsg, strTitle, recallIfInvalidInput);
        } else
        {
            return text;
        }
    }

    public static String formatStringWithLeadingZeros(String strToFormat, int maxLenOfString)
    {
        int leadingZerosNeededToFormatSize = maxLenOfString - strToFormat.length();
        for(int i = 0; i < leadingZerosNeededToFormatSize; i++)
        {
            strToFormat = (new StringBuilder("0")).append(strToFormat).toString();
            if(strToFormat.length() == maxLenOfString)
            {
                break;
            }
        }

        return strToFormat;
        Exception e;
        e;
        eop("formatStringWithLeadingZeros", strToFormat, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static void sop(String strToOutput)
    {
        System.out.println(strToOutput);
        System.out.flush();
    }

    public static void eop(String mtdName, String strMyClassName, Exception e, String errorMessage, boolean printStackTrace)
    {
        if(errorMessage == null || errorMessage.trim().equals(""))
        {
            sop((new StringBuilder("\nException caught in ")).append(mtdName).append(" mtd in ").append(strMyClassName).toString());
        } else
        {
            sop((new StringBuilder("\nException caught in ")).append(mtdName).append(" mtd in ").append(strMyClassName).append(" Error Message: ").append(errorMessage).toString());
        }
        if(printStackTrace)
        {
            e.printStackTrace(System.out);
        }
    }

    public static File querySelectFile(boolean openDialog, String dialogueTitle, int fileChooserSelectionMode, boolean thisLoadsCSV, boolean useFileFilter)
    {
        JFileChooser jfc;
        jfc = new JFileChooser(new File("."));
        jfc.setFileSelectionMode(fileChooserSelectionMode);
        jfc.setDialogTitle(dialogueTitle);
        if(thisLoadsCSV)
        {
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                public boolean accept(File fle)
                {
                    if(fle.isDirectory())
                    {
                        return true;
                    } else
                    {
                        String strFleName = fle.getName().toLowerCase();
                        return strFleName.endsWith(".csv");
                    }
                }

                public String getDescription()
                {
                    return "Comma Separated Values";
                }

            });
        } else
        if(useFileFilter)
        {
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                public boolean accept(File fle)
                {
                    String extension = "";
                    if(fle.isDirectory())
                    {
                        return true;
                    }
                    if(fle == null)
                    {
                        return false;
                    }
                    if(fle != null && fle.exists() && Drivers.getFileExtension(fle, false) != null)
                    {
                        extension = Drivers.getFileExtension(fle, false).replace(".", "");
                    }
                    return Drivers.lstAcceptableFileExtensionsForStego.contains(extension.toLowerCase());
                }

                public String getDescription()
                {
                    return "Specific Formats";
                }

            });
        }
        try
        {
            jfc.setCurrentDirectory(new File(".\\"));
        }
        catch(Exception exception) { }
        int selection = 0;
        if(openDialog)
        {
            selection = jfc.showOpenDialog(null);
        } else
        {
            selection = jfc.showSaveDialog(null);
        }
        if(selection != 0)
        {
            break MISSING_BLOCK_LABEL_190;
        }
        if(openDialog || !openDialog && !thisLoadsCSV)
        {
            return jfc.getSelectedFile();
        }
        return new File((new StringBuilder(String.valueOf(jfc.getSelectedFile().getAbsolutePath()))).append(".csv").toString());
        Exception e;
        e;
        eop("querySelectFile", strMyClassName, e, e.getMessage(), true);
        return null;
    }

    public static File[] querySelectMultipleFile(boolean openDialog, String dialogueTitle, int fileChooserSelectionMode, boolean thisLoadsCSV, boolean useFileFilter)
    {
        JFileChooser jfc;
        int selection;
        jfc = new JFileChooser(new File("."));
        jfc.setFileSelectionMode(fileChooserSelectionMode);
        jfc.setDialogTitle(dialogueTitle);
        jfc.setMultiSelectionEnabled(true);
        if(thisLoadsCSV)
        {
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                public boolean accept(File fle)
                {
                    if(fle.isDirectory())
                    {
                        return true;
                    } else
                    {
                        String strFleName = fle.getName().toLowerCase();
                        return strFleName.endsWith(".csv");
                    }
                }

                public String getDescription()
                {
                    return "Comma Separated Values";
                }

            });
        } else
        if(useFileFilter)
        {
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

                public boolean accept(File fle)
                {
                    String extension = "";
                    if(fle.isDirectory())
                    {
                        return true;
                    }
                    if(fle == null)
                    {
                        return false;
                    }
                    if(fle != null && fle.exists() && Drivers.getFileExtension(fle, false) != null)
                    {
                        extension = Drivers.getFileExtension(fle, false).replace(".", "");
                    }
                    return Drivers.lstAcceptableFileExtensionsForStego.contains(extension.toLowerCase());
                }

                public String getDescription()
                {
                    return "Multiple Formats";
                }

            });
        }
        try
        {
            jfc.setCurrentDirectory(new File(".\\"));
        }
        catch(Exception exception) { }
        selection = 0;
        if(openDialog)
        {
            selection = jfc.showOpenDialog(null);
        } else
        {
            selection = jfc.showSaveDialog(null);
        }
        if(selection == 0 && (openDialog || !openDialog && !thisLoadsCSV))
        {
            return jfc.getSelectedFiles();
        }
        break MISSING_BLOCK_LABEL_161;
        Exception e;
        e;
        eop("querySelectFile", strMyClassName, e, e.getMessage(), true);
        return null;
    }

    private File[] returnSelectedFiles(JFileChooser jfcToReturn)
    {
        return jfcToReturn.getSelectedFiles();
        Exception e;
        e;
        eop("returnSelectedFiles", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static int jop_Confirm(String strText, String strTitle)
    {
        return JOptionPane.showConfirmDialog(null, strText, strTitle, 0, 2);
        Exception e;
        e;
        eop("queryDialog", strMyClassName, e, e.getMessage(), true);
        return -1;
    }

    public static byte[] getFileExtension_ByteArray(File fle, boolean setToTextByDefault)
    {
        String fileExtensionFormatted;
        String fileExtension = getFileExtension(fle, true);
        fileExtensionFormatted = "";
        if(setToTextByDefault || fileExtension == null || fileExtension.trim().equals(""))
        {
            fileExtension = "txt";
        }
        if(fileExtension.length() != 4)
        {
            if(fileExtension.length() < 4)
            {
                fileExtensionFormatted = formatStringWithLeadingZeros(fileExtension, 4);
            }
            if(fileExtension.length() > 4)
            {
                fileExtensionFormatted = fileExtension.substring(0, 4);
            }
        } else
        {
            fileExtensionFormatted = fileExtension;
        }
        return fileExtensionFormatted.getBytes();
        NullPointerException npe;
        npe;
        if(!displayedInitialFileChooserError)
        {
            sop("NullPointerException caught in getFileExtension_ByteArray mtd in Drivers.  This " +
"seems to be a sporadic error, called when user first attempts to view the files " +
"in a directory. This does not affect funtionality of program.  Dismissing error." +
".."
);
            displayedInitialFileChooserError = true;
        }
        break MISSING_BLOCK_LABEL_124;
        Exception e;
        e;
        if(!displayedInitialFileChooserError)
        {
            eop("getFileExtension_ByteArray", strMyClassName, e, "Possibly null file passed in", true);
            displayedInitialFileChooserError = true;
        }
        return null;
    }

    public static String getFileExtension(File fle, boolean removeDot_Preceeding_Extension)
    {
        if(fle == null)
        {
            break MISSING_BLOCK_LABEL_81;
        }
        if(removeDot_Preceeding_Extension)
        {
            return fle.toString().substring(fle.toString().lastIndexOf(".") + 1);
        }
        return fle.toString().substring(fle.toString().lastIndexOf("."));
        NullPointerException npe;
        npe;
        if(!displayedInitialFileChooserError)
        {
            sop("NullPointerException caught in getFileExtension_ByteArray mtd in Drivers.  This " +
"seems to be a sporadic error, called when user first attempts to view the files " +
"in a directory. This does not affect funtionality of program.  Dismissing error." +
".."
);
            displayedInitialFileChooserError = true;
        }
        break MISSING_BLOCK_LABEL_81;
        Exception e;
        e;
        eop("getFileExtension", strMyClassName, e, "Possibly null file passed in", true);
        return null;
    }

    public static ArrayList getDirectoriesUnderSelectedDirectory(File fleDirectoryPath, boolean removeDirectoryContaining_Given_StringName, String strNameToExclude)
    {
        ArrayList alToReturn = new ArrayList();
        if(fleDirectoryPath == null)
        {
            throw new Exception("Null value passed in");
        }
        if(fleDirectoryPath.isFile())
        {
            throw new Exception("Directory path was specified; instead, received path to a file");
        }
        FileFilter filter = new FileFilter() {

            public boolean accept(File file)
            {
                return file.isDirectory();
            }

        };
        File fleFilePaths[] = fleDirectoryPath.listFiles(filter);
        String strDirPath = "";
        for(int i = 0; i < fleFilePaths.length; i++)
        {
            if(fleFilePaths[i].isDirectory())
            {
                if(removeDirectoryContaining_Given_StringName)
                {
                    strDirPath = fleFilePaths[i].getCanonicalPath();
                    if(strDirPath == null || strNameToExclude == null || !strDirPath.toUpperCase().contains(strNameToExclude.toUpperCase()))
                    {
                        alToReturn.add(fleFilePaths[i]);
                    }
                } else
                {
                    alToReturn.add(fleFilePaths[i]);
                }
            }
        }

        return alToReturn;
        Exception e;
        e;
        eop("getDirectoriesUnderSelectedDirectory", strMyClassName, e, e.getMessage(), true);
        return null;
    }

    public static ArrayList getFilesUnderSelectedDirectory(File fleDirectoryPath, boolean limitFilesTo_ONLY_AcceptableFileExtensions)
    {
        ArrayList alToReturn = new ArrayList();
        if(fleDirectoryPath == null)
        {
            throw new Exception("Null value passed in");
        }
        if(fleDirectoryPath.isFile())
        {
            throw new Exception("Directory path was specified; instead, received path to a file");
        }
        File fleFilePaths[] = fleDirectoryPath.listFiles();
        String strFleExtension = "";
        for(int i = 0; i < fleFilePaths.length; i++)
        {
            if(fleFilePaths[i].isFile())
            {
                if(limitFilesTo_ONLY_AcceptableFileExtensions)
                {
                    strFleExtension = getFileExtension(fleFilePaths[i], false).replace(".", "");
                    if(lstAcceptableFileExtensionsForStego.contains(strFleExtension.toLowerCase()))
                    {
                        alToReturn.add(fleFilePaths[i]);
                    }
                } else
                {
                    alToReturn.add(fleFilePaths[i]);
                }
            }
        }

        return alToReturn;
        Exception e;
        e;
        eop("getFilesUnderSelectedDirectory", strMyClassName, e, e.getMessage(), true);
        return null;
    }

    public static ArrayList getFilesUnderSelectedDirectory(File fleDirectoryPath, String acceptableExtensions[])
    {
        ArrayList alToReturn;
        java.util.List lstAcceptableFileExtensions;
        alToReturn = new ArrayList();
        lstAcceptableFileExtensions = null;
        if(acceptableExtensions != null)
        {
            lstAcceptableFileExtensions = Arrays.asList(acceptableExtensions);
        }
        if(fleDirectoryPath == null)
        {
            throw new Exception("Null value passed in");
        }
        if(fleDirectoryPath.isFile())
        {
            throw new Exception("Directory path was specified; instead, received path to a file");
        }
        File fleFilePaths[] = fleDirectoryPath.listFiles();
        String strFleExtension = "";
        for(int i = 0; i < fleFilePaths.length; i++)
        {
            if(fleFilePaths[i].isFile())
            {
                if(lstAcceptableFileExtensions != null)
                {
                    strFleExtension = getFileExtension(fleFilePaths[i], false).replace(".", "");
                    if(lstAcceptableFileExtensions.contains(strFleExtension.toLowerCase()) || lstAcceptableFileExtensions.contains(strFleExtension.toUpperCase()))
                    {
                        alToReturn.add(fleFilePaths[i]);
                    }
                } else
                {
                    alToReturn.add(fleFilePaths[i]);
                }
            }
        }

        return alToReturn;
        Exception e;
        e;
        eop("getFilesUnderSelectedDirectory with acceptableExtensions array", strMyClassName, e, e.getMessage(), true);
        return null;
    }

    public static String getFormattedFileSize_String(long fileSize_bytes)
    {
        double fileSize;
        DecimalFormat formatter;
        fileSize = fileSize_bytes;
        formatter = new DecimalFormat("###.##");
        if(fileSize_bytes < 1000L)
        {
            return (new StringBuilder(String.valueOf(formatter.format(fileSize)))).append(" B").toString();
        }
        if(fileSize_bytes > 1L && (double)fileSize_bytes < 99000D)
        {
            return (new StringBuilder(String.valueOf(formatter.format((double)fileSize_bytes / 1000D)))).append(" KB").toString();
        }
        if((double)fileSize_bytes > 1000D && (double)fileSize_bytes < 99000000D)
        {
            return (new StringBuilder(String.valueOf(formatter.format((double)fileSize_bytes / 1000000D)))).append(" MB").toString();
        }
        if((double)fileSize_bytes > 1000000D && (double)fileSize_bytes < 99000000000D)
        {
            return (new StringBuilder(String.valueOf(formatter.format((double)fileSize_bytes / 1000000000D)))).append(" GB").toString();
        }
        if((double)fileSize_bytes > 1000000000D && (double)fileSize_bytes < 99000000000000D)
        {
            return (new StringBuilder(String.valueOf(formatter.format((double)fileSize_bytes / 1000000000000D)))).append(" TB").toString();
        }
        if((double)fileSize_bytes > 1000000000000D && (double)fileSize_bytes < 99000000000000000D)
        {
            return (new StringBuilder(String.valueOf(formatter.format((double)fileSize_bytes / 1000000000000000D)))).append(" PB").toString();
        }
        return (new StringBuilder(String.valueOf(formatter.format(fileSize_bytes)))).append(" B").toString();
        Exception e;
        e;
        eop("getFormattedFileSize_String", strMyClassName, e, e.getMessage(), true);
        sop("Unable to determine File Size");
        return "UNKNOWN";
    }

    public static String calculateTotalFileSizeFromCarrierImages_String(ArrayList alToSearch)
    {
        long lastGoodKnownSize;
        long totalFileSize;
        lastGoodKnownSize = 0L;
        String strSize = "";
        totalFileSize = 0L;
        for(int i = 0; i < alToSearch.size(); i++)
        {
            lastGoodKnownSize = totalFileSize;
            totalFileSize += ((JPanel_AddCarrierImagePath_OR_UploadDestination)alToSearch.get(i)).getMyCarrierFileSize();
        }

        return (new StringBuilder()).append(totalFileSize).toString();
        Exception e;
        e;
        eop("calculateTotalFileSizeFromCarrierImages_String", strMyClassName, e, e.getMessage(), true);
        return (new StringBuilder("< ")).append(getFormattedFileSize_String(lastGoodKnownSize)).toString();
    }

    public static String calculateTotalEmbedSizeFromCarrierImages_String(ArrayList alToSearch, boolean printVerificationInformation)
    {
        long lastGoodKnownSize;
        long totalFileSize;
        lastGoodKnownSize = 0L;
        String strSize = "";
        totalFileSize = 0L;
        for(int i = 0; i < alToSearch.size(); i++)
        {
            lastGoodKnownSize = totalFileSize;
            totalFileSize += ((JPanel_AddCarrierImagePath_OR_UploadDestination)alToSearch.get(i)).getMyEmbedContentinCarrierFileSize(printVerificationInformation);
        }

        return (new StringBuilder()).append(totalFileSize).toString();
        Exception e;
        e;
        eop("calculateTotalFileSizeFromCarrierImages_String", strMyClassName, e, e.getMessage(), true);
        return (new StringBuilder("< ")).append(getFormattedFileSize_String(lastGoodKnownSize)).toString();
    }

    public static long calculateTotalFileSizeInBytesFromCarrierImages_Long(ArrayList alToSearch)
    {
        long lastGoodKnownSize;
        long totalFileSize;
        lastGoodKnownSize = 0L;
        String strSize = "";
        totalFileSize = 0L;
        for(int i = 0; i < alToSearch.size(); i++)
        {
            lastGoodKnownSize = totalFileSize;
            totalFileSize += ((JPanel_AddCarrierImagePath_OR_UploadDestination)alToSearch.get(i)).getMyCarrierFileSize();
        }

        return totalFileSize;
        Exception e;
        e;
        eop("calculateTotalFileSizeInBytesFromCarrierImages_Long", strMyClassName, e, e.getMessage(), true);
        return lastGoodKnownSize;
    }

    public static long calculateTotalEmbedFileSizeInBytesFromCarrierImages_Long(ArrayList alToSearch, boolean printVerificationInformation)
    {
        long lastGoodKnownSize;
        long totalFileSize;
        lastGoodKnownSize = 0L;
        String strSize = "";
        totalFileSize = 0L;
        for(int i = 0; i < alToSearch.size(); i++)
        {
            lastGoodKnownSize = totalFileSize;
            totalFileSize += ((JPanel_AddCarrierImagePath_OR_UploadDestination)alToSearch.get(i)).getMyEmbedContentinCarrierFileSize(printVerificationInformation);
        }

        return totalFileSize;
        Exception e;
        e;
        eop("calculateTotalFileSizeInBytesFromCarrierImages_Long", strMyClassName, e, e.getMessage(), true);
        return lastGoodKnownSize;
    }

    public static boolean copyFilesToDirectory(ArrayList alSourceFilesToCopy, File fleDestinationDirectory)
    {
        if(alSourceFilesToCopy != null && alSourceFilesToCopy.size() >= 1 && fleDestinationDirectory != null && fleDestinationDirectory.isDirectory())
        {
            break MISSING_BLOCK_LABEL_45;
        }
        sop((new StringBuilder("No files to copy for path: ")).append(fleDestinationDirectory).toString());
        return true;
        try
        {
            Process p = null;
            for(int i = 0; i < alSourceFilesToCopy.size(); i++)
            {
                p = Runtime.getRuntime().exec((new StringBuilder("cmd /c COPY /Y \"")).append(alSourceFilesToCopy.get(i)).append("\"").append(" ").append("\"").append(fleDestinationDirectory).append("\"").toString());
            }

        }
        catch(Exception e)
        {
            eop("copyFilesToDirectory", strMyClassName, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static boolean launchFolder(File fleToOpen)
    {
        if(fleToOpen != null && fleToOpen.exists())
        {
            break MISSING_BLOCK_LABEL_22;
        }
        jop_Error("No Path to Launch!!!", "Launch Path Not Specified");
        return false;
        try
        {
            sop((new StringBuilder("Opening: ")).append(fleToOpen.getCanonicalPath()).toString());
            Process p = Runtime.getRuntime().exec((new StringBuilder("explorer.exe \"")).append(fleToOpen.getCanonicalPath()).append("\"").toString());
        }
        catch(Exception e)
        {
            eop("launchFolder", strMyClassName, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static File ensureTempFolderExists(File fleDirectoryPath)
    {
        String strTempDirName;
        File fleTemp;
        strTempDirName = "temp";
        fleTemp = null;
        if(fleDirectoryPath.getCanonicalFile().toString().endsWith(strTempDirName))
        {
            return fleDirectoryPath;
        }
        if(fleDirectoryPath.getCanonicalFile().toString().endsWith(System.getProperty("file.separator")))
        {
            fleTemp = new File((new StringBuilder()).append(fleDirectoryPath.getCanonicalFile()).append(strTempDirName).toString());
        } else
        {
            fleTemp = new File((new StringBuilder()).append(fleDirectoryPath.getCanonicalFile()).append(System.getProperty("file.separator")).append(strTempDirName).toString());
        }
        return ensureFolderExists(fleTemp);
        Exception e;
        e;
        eop("ensureTempFolderExists", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static File ensureFolderExists(File fleDirectoryPath)
    {
        if(!fleDirectoryPath.exists())
        {
            fleDirectoryPath.mkdir();
        }
        return fleDirectoryPath;
        Exception e;
        e;
        eop("ensureFolderExists", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static boolean writeSourceTextToDisk(String sourceText, File fleOutPath)
    {
        if(fleOutPath != null)
        {
            break MISSING_BLOCK_LABEL_12;
        }
        sop("NO FILE PATH WAS SPECIFIED!");
        return false;
        try
        {
            PrintWriter pwOut = new PrintWriter(new BufferedOutputStream(new FileOutputStream(fleOutPath)));
            pwOut.println(sourceText);
            pwOut.flush();
            pwOut.close();
            sop((new StringBuilder("File successfully written to: ")).append(fleOutPath.getCanonicalFile()).toString());
            jop_Message((new StringBuilder("File successfully written to: ")).append(fleOutPath.getCanonicalFile()).toString(), "Save Complete");
        }
        catch(Exception e)
        {
            eop("writeByteArrayToDisk", strMyClassName, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static File writeImage_Fully(String outputFileNameAndExtension, File directoryToWrite, byte arrToWrite[])
    {
        File fleOut;
        fleOut = null;
        if(outputFileNameAndExtension == null || outputFileNameAndExtension.trim().length() < 1 || !directoryToWrite.exists() || !directoryToWrite.isDirectory())
        {
            throw new Exception("Parameters passed into writeImage were not valid");
        }
        if(directoryToWrite.getCanonicalFile().toString().endsWith(System.getProperty("file.separator")))
        {
            fleOut = new File((new StringBuilder()).append(directoryToWrite.getCanonicalFile()).append(outputFileNameAndExtension).toString());
        } else
        {
            fleOut = new File((new StringBuilder()).append(directoryToWrite.getCanonicalFile()).append(System.getProperty("file.separator")).append(outputFileNameAndExtension).toString());
        }
        FileOutputStream fos = new FileOutputStream(fleOut);
        fos.write(arrToWrite);
        fos.flush();
        fos.close();
        sop((new StringBuilder("File successfully written to: ")).append(fleOut.getCanonicalFile()).toString());
        return fleOut;
        Exception e;
        e;
        eop("writeImage_Fully", outputFileNameAndExtension, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static byte[] readImage_Fully(File fleToRead)
    {
        byte arrCarrierImage[];
        sop((new StringBuilder("Reading Carrier Image: ")).append(fleToRead).toString());
        if(fleToRead.length() > 0x7fffffffL)
        {
            jop_Error((new StringBuilder("Error!!!\n\nCarrier Image(")).append(fleToRead.getName()).append(") is too large to read in and index").toString(), "File Too Large");
            throw new IOException((new StringBuilder("Error!!!\n\nCarrier Image(")).append(fleToRead.getName()).append(") is too large to read in and index").toString());
        }
        arrCarrierImage = new byte[(int)fleToRead.length()];
        InputStream is = new FileInputStream(fleToRead);
        int offset = 0;
        for(int numBytesRead = 0; offset < arrCarrierImage.length && (numBytesRead = is.read(arrCarrierImage, offset, arrCarrierImage.length - offset)) >= 0; offset += numBytesRead) { }
        if(offset < arrCarrierImage.length)
        {
            throw new IOException((new StringBuilder("File (")).append(fleToRead.getName()).append(") not fully read!").toString());
        }
        is.close();
        sop((new StringBuilder("* * * Finished reading in carrier image.  No Errors reported.  Num Bytes read in" +
": "
)).append(arrCarrierImage.length).toString());
        return arrCarrierImage;
        Exception e;
        e;
        eop("readImage_Fully", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static byte[] readImage_Offset(File fleToRead, int offset, int numBytesToRead)
    {
        byte arrCarrierImage[];
        sop((new StringBuilder("Reading Image: ")).append(fleToRead).toString());
        if(fleToRead.length() > 0x7fffffffL)
        {
            jop_Error((new StringBuilder("Error!!!\n\nSource Image(")).append(fleToRead.getName()).append(") is too large to read in and index").toString(), "File Too Large");
            throw new IOException((new StringBuilder("Error!!!\n\nSource Image(")).append(fleToRead.getName()).append(") is too large to read in and index").toString());
        }
        arrCarrierImage = new byte[numBytesToRead];
        InputStream is = new FileInputStream(fleToRead);
        int numBytesRead = 0;
        int endIndex = offset + numBytesToRead;
        int numberBytesActuallyReadIn;
        for(numberBytesActuallyReadIn = 0; offset < endIndex && (numBytesRead = is.read(arrCarrierImage, offset, endIndex - offset)) >= 0; numberBytesActuallyReadIn += numBytesRead)
        {
            offset += numBytesRead;
        }

        if(numberBytesActuallyReadIn < numBytesToRead)
        {
            throw new IOException((new StringBuilder("File (")).append(fleToRead.getName()).append(") not fully read!").toString());
        }
        is.close();
        sop((new StringBuilder("* * * Finished reading in source image.  No Errors reported.  Num Bytes read in:" +
" "
)).append(numberBytesActuallyReadIn).toString());
        return arrCarrierImage;
        Exception e;
        e;
        eop("readCarrierImage", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static ArrayList populateRandomLocationToEmbedBits(int numLocationsToPopulate, int seed, int fleSize)
    {
        ArrayList alToPopulate;
        Random pseudoRandom;
        alToPopulate = new ArrayList(1);
        pseudoRandom = new Random(seed);
        int randNum = 0;
        while(alToPopulate.size() != numLocationsToPopulate) 
        {
            int randNum = Math.abs(pseudoRandom.nextInt() % fleSize);
            if(!alToPopulate.contains(Integer.valueOf(randNum)) || randNum <= 30)
            {
                alToPopulate.add(Integer.valueOf(randNum));
            }
        }
        return alToPopulate;
        Exception e;
        e;
        eop("populateRandomLocationToEmbedBits", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    public static int[] populateByteTo_INT_BitArray(byte byteToEmbed)
    {
        int arrToReturn[] = new int[8];
        int byteToReturn = byteToEmbed;
        try
        {
            arrToReturn[0] = byteToReturn >>> 7 & 1;
            arrToReturn[1] = byteToReturn >>> 6 & 1;
            arrToReturn[2] = byteToReturn >>> 5 & 1;
            arrToReturn[3] = byteToReturn >>> 4 & 1;
            arrToReturn[4] = byteToReturn >>> 3 & 1;
            arrToReturn[5] = byteToReturn >>> 2 & 1;
            arrToReturn[6] = byteToReturn >>> 1 & 1;
            arrToReturn[7] = byteToReturn >>> 0 & 1;
        }
        catch(Exception e)
        {
            eop("populateByteTo_INT_BitArray", strMyClassName, e, e.getLocalizedMessage(), true);
        }
        return arrToReturn;
    }

    public static byte[] intToByteArray(int value)
    {
        return (new byte[] {
            (byte)(value >>> 24), (byte)(value >>> 16), (byte)(value >>> 8), (byte)value
        });
    }

    public static String byteToTwosComplementString(byte byteToComplement[])
    {
        char arrOnesComp[] = (char[])null;
        try
        {
            String curr = (new BigInteger(byteToComplement)).toString(2);
            String newCurr = curr.replace("-", "");
            String onesComp = "";
            int bit = 0;
            char arrNewCurr[] = newCurr.toCharArray();
            arrOnesComp = new char[newCurr.length()];
            for(int j = 0; j < arrNewCurr.length; j++)
            {
                if(arrNewCurr[j] == '0')
                {
                    arrOnesComp[j] = '1';
                } else
                {
                    arrOnesComp[j] = '0';
                }
            }

            for(int m = arrOnesComp.length - 1; m > 0; m--)
            {
                if(arrOnesComp[m] == '0')
                {
                    arrOnesComp[m] = '1';
                    break;
                }
                arrOnesComp[m] = '0';
            }

        }
        catch(Exception e)
        {
            eop("byteToTwosComplementString", strMyClassName, e, e.getLocalizedMessage(), true);
        }
        String str = new String(arrOnesComp);
        String strToReturn = formatBinString(str);
        return (new StringBuilder("1")).append(strToReturn.substring(1)).toString();
    }

    public static boolean writeByteArrayToDisk(byte byteArrayToWrite[], boolean makeArraySmallerByOneIndex, String strOutFileName)
    {
        try
        {
            byte smallerByteArray[] = (byte[])null;
            if(makeArraySmallerByOneIndex)
            {
                smallerByteArray = new byte[byteArrayToWrite.length - 1];
                for(int i = 0; i < smallerByteArray.length; i++)
                {
                    smallerByteArray[i] = byteArrayToWrite[i];
                }

            } else
            {
                smallerByteArray = byteArrayToWrite;
            }
            FileOutputStream fos = new FileOutputStream(new File(strOutFileName));
            fos.write(smallerByteArray);
            fos.flush();
            fos.close();
        }
        catch(Exception e)
        {
            eop("writeByteArrayToDisk", strMyClassName, e, e.getLocalizedMessage(), true);
            return false;
        }
        return true;
    }

    public static File createAnalyzedFolder(File fleCarrierImage, File fleTopFolder_CarrierImage)
    {
        File fleExpectedAnalyzedFolderPath;
        String strTopFolderPath = fleTopFolder_CarrierImage.getCanonicalPath();
        if(!strTopFolderPath.endsWith(System.getProperty("file.separator")))
        {
            fleExpectedAnalyzedFolderPath = new File((new StringBuilder(String.valueOf(strTopFolderPath))).append(System.getProperty("file.separator")).append("Analyzed").toString());
        } else
        {
            fleExpectedAnalyzedFolderPath = new File((new StringBuilder(String.valueOf(strTopFolderPath))).append("Analyzed").toString());
        }
        if(!fleExpectedAnalyzedFolderPath.exists())
        {
            fleExpectedAnalyzedFolderPath.mkdir();
        }
        return fleExpectedAnalyzedFolderPath;
        Exception e;
        e;
        eop("createAnalyzedFolder", strMyClassName, e, e.getLocalizedMessage(), true);
        return null;
    }

    static 
    {
        lstAcceptableFileExtensionsForStego = Arrays.asList(acceptableFileExtensionsForStego);
        lstSpecialFormats_jpgPngGif = Arrays.asList(specialFormats_jpgPngGif);
    }
}
