Class Utils


  • public class Utils
    extends Object
    Utils contains a few commonly occurring methods.
    Author:
    richardrodgers
    • Method Detail

      • checksum

        public static String checksum​(File file,
                                      String algorithm)
                               throws IOException
        Calculates and returns a checksum for the passed file using the passed algorithm.
        Parameters:
        file - file on which to calculate checksum
        algorithm - string for algorithm: 'MD5', 'SHA1', etc
        Returns:
        checksum string of the calculated checksum
        Throws:
        IOException - if IO error
      • checksum

        public static String checksum​(InputStream in,
                                      String algorithm)
                               throws IOException
        Calculates and returns a checksum for the passed IO stream using the passed algorithm.
        Parameters:
        in - input stream on which to calculate checksum
        algorithm - string for algorithm: 'MD5', 'SHA1', etc
        Returns:
        checksum string of the calculated checksum
        Throws:
        IOException - if IO error
      • toHex

        public static String toHex​(byte[] data)
      • copy

        public static void copy​(File inFile,
                                File outFile)
                         throws IOException
        Performs a buffered copy from one file into another.
        Parameters:
        inFile - input file
        outFile - output file
        Throws:
        IOException - if IO error
      • copy

        public static void copy​(InputStream in,
                                OutputStream out)
                         throws IOException
        Performs a buffered copy from one IO stream into another. Note that stream closure is responsibility of caller.
        Parameters:
        in - input stream
        out - output stream
        Throws:
        IOException - if IO error