Class Hasher


  • public class Hasher
    extends java.lang.Object
    Utility class to generate hashes/checksums for binary files. Typically used to generate a hashes for .class files to compare those files for equality.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String classFilePath
      the path to the .class file.
    • Constructor Summary

      Constructors 
      Constructor Description
      Hasher​(java.lang.String classFilePath)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void closeAll​(java.io.Closeable... closeables)  
      java.lang.String generateHash​(org.apache.maven.artifact.Artifact artifact)  
      private java.lang.String hashForFileInDirectory​(java.io.File artifactFile)  
      private java.lang.String hashForFileInJar​(java.io.File artifactFile)  
      • Methods inherited from class java.lang.Object

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

      • classFilePath

        private final java.lang.String classFilePath
        the path to the .class file. Example: org/apache/maven/Stuff.class
    • Constructor Detail

      • Hasher

        public Hasher​(java.lang.String classFilePath)
        Constructor.
        Parameters:
        classFilePath - The path to the .class file. This is the file we'll generate a hash for. Example: org/apache/maven/Stuff.class
    • Method Detail

      • generateHash

        public java.lang.String generateHash​(org.apache.maven.artifact.Artifact artifact)
        Parameters:
        artifact - The artifact (example: jar file) which contains the classFilePath. We'll generate a hash for the class file inside this artifact.
        Returns:
        generate a hash/checksum for the .class file in the provided artifact.
      • hashForFileInDirectory

        private java.lang.String hashForFileInDirectory​(java.io.File artifactFile)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • hashForFileInJar

        private java.lang.String hashForFileInJar​(java.io.File artifactFile)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • closeAll

        private void closeAll​(java.io.Closeable... closeables)
                       throws java.io.IOException
        Throws:
        java.io.IOException