Class CommonUtil


  • public class CommonUtil
    extends Object
    Common utilities for OpenStego
    • Method Detail

      • streamToBytes

        public static byte[] streamToBytes​(InputStream is)
                                    throws OpenStegoException
        Method to get byte array data from given InputStream
        Parameters:
        is - InputStream to read
        Returns:
        Stream data as byte array
        Throws:
        OpenStegoException - Processing issues
      • fileToBytes

        public static byte[] fileToBytes​(File file)
                                  throws OpenStegoException
        Method to get byte array data from given file
        Parameters:
        file - File to read
        Returns:
        File data as byte array
        Throws:
        OpenStegoException - Processing issues
      • writeFile

        public static void writeFile​(byte[] fileData,
                                     String fileName)
                              throws OpenStegoException
        Method to write file data to disk
        Parameters:
        fileData - File data
        fileName - File name (If this is null, then data is written to stdout)
        Throws:
        OpenStegoException - Processing issues
      • writeFile

        public static void writeFile​(byte[] fileData,
                                     File file)
                              throws OpenStegoException
        Method to write file data to disk
        Parameters:
        fileData - File data
        file - File object (If this is null, then data is written to stdout)
        Throws:
        OpenStegoException - Processing issues
      • setEnabled

        public static void setEnabled​(JTextField textField,
                                      boolean enabled)
        Method to enable/disable a Swing JTextField object
        Parameters:
        textField - Swing JTextField object
        enabled - Flag to indicate whether to enable or disable the object
      • parseFileList

        public static List<File> parseFileList​(String fileList,
                                               String delimiter)
        Method to parse a delimiter separated list of files into arraylist of filenames. It supports wildcard characters "*" and "?" within the filenames.
        Parameters:
        fileList - Delimiter separated list of filenames
        delimiter - Delimiter for tokenization
        Returns:
        List of filenames after tokenizing and wildcard expansion
      • byteToInt

        public static int byteToInt​(int b)
        Byte to Int converter
        Parameters:
        b - Input byte value
        Returns:
        Int value
      • floorHalf

        public static int floorHalf​(int num)
        Returns the floor of the half of the input value
        Parameters:
        num - Input number
        Returns:
        Floor of the half of the input number
      • ceilingHalf

        public static int ceilingHalf​(int num)
        Returns the ceiling of the half of the input value
        Parameters:
        num - Input number
        Returns:
        Ceiling of the half of the input number
      • mod

        public static int mod​(int num,
                              int div)
        Returns the modulus of the input value (taking care of the sign of the value)
        Parameters:
        num - Input number
        div - Divisor for modulus
        Returns:
        Modulus of num by div