Class CommonUtil


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int byteToInt​(int b)
      Byte to Int converter
      static int ceilingHalf​(int num)
      Returns the ceiling of the half of the input value
      static int floorHalf​(int num)
      Returns the floor of the half of the input value
      static byte[] getFileBytes​(File file)
      Method to get byte array data from given file
      static byte[] getStreamBytes​(InputStream is)
      Method to get byte array data from given InputStream
      static double max​(double x, double y)
      Get maximum of two given values
      static int max​(int x, int y)
      Get maximum of two given values
      static double min​(double x, double y)
      Get minimum of two given values
      static int min​(int x, int y)
      Get minimum of two given values
      static int mod​(int num, int div)
      Returns the modulus of the input value (taking care of the sign of the value)
      static List<File> parseFileList​(String fileList, String delimiter)
      Method to parse a delimiter separated list of files into arraylist of filenames.
      static void setEnabled​(JTextField textField, boolean enabled)
      Method to enable/disable a Swing JTextField object
      static void writeFile​(byte[] fileData, File file)
      Method to write file data to disk
      static void writeFile​(byte[] fileData, String fileName)
      Method to write file data to disk
    • Method Detail

      • getStreamBytes

        public static byte[] getStreamBytes​(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
      • getFileBytes

        public static byte[] getFileBytes​(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
      • 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
      • 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
      • 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
      • max

        public static int max​(int x,
                              int y)
        Get maximum of two given values
        Parameters:
        x - Value 1
        y - value 2
        Returns:
        Max of the two values
      • max

        public static double max​(double x,
                                 double y)
        Get maximum of two given values
        Parameters:
        x - Value 1
        y - value 2
        Returns:
        Max of the two values
      • min

        public static int min​(int x,
                              int y)
        Get minimum of two given values
        Parameters:
        x - Value 1
        y - value 2
        Returns:
        Min of the two values
      • min

        public static double min​(double x,
                                 double y)
        Get minimum of two given values
        Parameters:
        x - Value 1
        y - value 2
        Returns:
        Min of the two values