Class ChecksumHelper


  • public final class ChecksumHelper
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.String,​java.lang.String> algorithms  
      private static int BUFFER_SIZE  
      private static char[] CHARS  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ChecksumHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String byteArrayToHexString​(byte[] in)
      Convert a byte[] array to readable string format.
      static void check​(java.io.File dest, java.io.File checksumFile, java.lang.String algorithm)
      Checks the checksum of the given file against the given checksumFile, and throws an IOException if the checksum is not compliant
      private static byte[] compute​(java.io.File f, java.lang.String algorithm)  
      static java.lang.String computeAsString​(java.io.File f, java.lang.String algorithm)  
      private static java.security.MessageDigest getMessageDigest​(java.lang.String algorithm)  
      private static boolean isAlgorithmSupportedInJRE​(java.lang.String algorithm)  
      static boolean isKnownAlgorithm​(java.lang.String algorithm)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • algorithms

        private static final java.util.Map<java.lang.String,​java.lang.String> algorithms
      • CHARS

        private static final char[] CHARS
    • Constructor Detail

      • ChecksumHelper

        private ChecksumHelper()
    • Method Detail

      • isAlgorithmSupportedInJRE

        private static boolean isAlgorithmSupportedInJRE​(java.lang.String algorithm)
      • check

        public static void check​(java.io.File dest,
                                 java.io.File checksumFile,
                                 java.lang.String algorithm)
                          throws java.io.IOException
        Checks the checksum of the given file against the given checksumFile, and throws an IOException if the checksum is not compliant
        Parameters:
        dest - the file to test
        checksumFile - the file containing the expected checksum
        algorithm - the checksum algorithm to use
        Throws:
        java.io.IOException - if an IO problem occur while reading files or if the checksum is not compliant
      • computeAsString

        public static java.lang.String computeAsString​(java.io.File f,
                                                       java.lang.String algorithm)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • compute

        private static byte[] compute​(java.io.File f,
                                      java.lang.String algorithm)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • isKnownAlgorithm

        public static boolean isKnownAlgorithm​(java.lang.String algorithm)
      • getMessageDigest

        private static java.security.MessageDigest getMessageDigest​(java.lang.String algorithm)
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] in)
        Convert a byte[] array to readable string format. This makes the "hex" readable!
        Parameters:
        in - byte[] buffer to convert to string format
        Returns:
        result String buffer in String format