Class Hasher


  • public abstract class Hasher
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Hasher()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract byte[] asBytes()
      Closes the hasher (if not yet closed) and returns the result as bytes.
      abstract java.lang.String asHex()
      Closes the hasher (if not yet closed) and returns the result as a hex-encoded value
      abstract boolean isCompleted()  
      static Hasher md5()
      Creates a new (open) MD5 hasher that is ready to accept a stream of bytes.
      static Hasher md5​(java.io.File file)
      Creates a new (closed) MD5 hasher that has computed the digest for the file.
      static Hasher md5​(java.io.InputStream input)
      Creates a new (closed) MD5 hasher that has computed the digest for the input.
      static Hasher md5​(java.nio.file.Path file)
      Creates a new (closed) MD5 hasher that has computed the digest for the file.
      abstract Hasher update​(byte[] buffer)
      Updates the hash/digest with the supplied byte buffer.
      abstract Hasher update​(byte[] buffer, int offset, int length)
      Updates the hash/digest with the supplied byte buffer.
      abstract Hasher update​(java.nio.ByteBuffer buffer)
      Updates the hash/digest with the supplied byte buffer.
      • Methods inherited from class java.lang.Object

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

      • Hasher

        public Hasher()
    • Method Detail

      • update

        public abstract Hasher update​(java.nio.ByteBuffer buffer)
        Updates the hash/digest with the supplied byte buffer. The hasher must still be OPEN otherwise this will throw an exception.
        Parameters:
        buffer -
        Returns:
      • update

        public abstract Hasher update​(byte[] buffer)
        Updates the hash/digest with the supplied byte buffer. The hasher must still be OPEN otherwise this will throw an exception.
        Parameters:
        buffer -
        Returns:
      • update

        public abstract Hasher update​(byte[] buffer,
                                      int offset,
                                      int length)
        Updates the hash/digest with the supplied byte buffer. The hasher must still be OPEN otherwise this will throw an exception.
        Parameters:
        buffer -
        offset -
        length -
        Returns:
      • isCompleted

        public abstract boolean isCompleted()
      • asBytes

        public abstract byte[] asBytes()
        Closes the hasher (if not yet closed) and returns the result as bytes.
        Returns:
      • asHex

        public abstract java.lang.String asHex()
        Closes the hasher (if not yet closed) and returns the result as a hex-encoded value
        Returns:
      • md5

        public static Hasher md5()
        Creates a new (open) MD5 hasher that is ready to accept a stream of bytes.
        Returns:
      • md5

        public static Hasher md5​(java.io.File file)
                          throws java.io.IOException
        Creates a new (closed) MD5 hasher that has computed the digest for the file.
        Parameters:
        file - The file to compute MD5 digest
        Returns:
        Throws:
        java.io.IOException
      • md5

        public static Hasher md5​(java.nio.file.Path file)
                          throws java.io.IOException
        Creates a new (closed) MD5 hasher that has computed the digest for the file.
        Parameters:
        file - The file to compute MD5 digest
        Returns:
        Throws:
        java.io.IOException
      • md5

        public static Hasher md5​(java.io.InputStream input)
                          throws java.io.IOException
        Creates a new (closed) MD5 hasher that has computed the digest for the input.
        Parameters:
        input - The input to compute MD5 digest. The input will be read until its exhausted. Caller is responsible for closing the input!
        Returns:
        Throws:
        java.io.IOException