Class Digest


  • public class Digest
    extends java.lang.Object
    Digest implementation
    • Constructor Detail

      • Digest

        public Digest​(DigestType algo)
        Create one DigestLight
        Parameters:
        algo - the algorithm to use
        Throws:
        java.lang.IllegalArgumentException - if null or unknown algorithm
      • Digest

        public Digest​(java.lang.String digest,
                      DigestType algo)
        Create one DigestLight from parameter
        Parameters:
        digest - as String to create
        algo - the algorithm to use
        Throws:
        java.lang.IllegalArgumentException - if null or unknown algorithm or if digest is null or empty
    • Method Detail

      • type

        public final DigestType type()
        Returns:
        the associated digest type
      • update

        public final Digest update​(byte[] bytes)
        Parameters:
        bytes - the bytes from which to update
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if bytes null
      • update

        public final Digest update​(byte[] bytes,
                                   int offset,
                                   int length)
        Parameters:
        bytes - the bytes from which to update
        offset - the offset position
        length - the length
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if bytes null, offset < 0, length < 0
      • update

        public final Digest update​(java.nio.ByteBuffer buffer)
        Parameters:
        buffer - for updating Digest
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if buffer null
      • update

        public final Digest update​(java.lang.String value)
        Parameters:
        value - the String value from which to update
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - value null
      • update

        public final Digest update​(java.io.File in)
                            throws java.io.IOException
        Parameters:
        in - the file from which to update
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - in null
      • update

        public final Digest update​(java.io.File in,
                                   long start,
                                   long limit)
                            throws java.io.IOException
        Parameters:
        in - the file from which to update
        start - the position to start
        limit - if less than 0, means all
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - in null, start < 0
      • update

        public final Digest update​(java.io.InputStream inputStream)
                            throws java.io.IOException
        Parameters:
        inputStream - the inputstream from which to update using default chunksize
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - inputstream null
      • update

        public final Digest update​(java.io.InputStream inputStream,
                                   int chunkSize)
                            throws java.io.IOException
        Parameters:
        inputStream - the inputstream from which to update
        chunkSize - the chunksize to use
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - inputstream null, chunksize < 1
      • update

        public final Digest update​(java.io.InputStream inputStream,
                                   int chunkSize,
                                   long limit)
                            throws java.io.IOException
        Parameters:
        inputStream - the inputstream from which to update
        chunkSize - the chunksize to use
        limit - if less than 0, means all
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - inputstream null, chunksize < 1
      • update

        public final Digest update​(java.nio.channels.FileChannel fileChannelInputStream)
                            throws java.io.IOException
        Parameters:
        fileChannelInputStream - the FileChannel inputstream from which to update
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - fileChannelIinputStream null
      • update

        public final Digest update​(java.nio.channels.FileChannel fileChannelInputStream,
                                   long start,
                                   int chunkSize,
                                   long limit)
                            throws java.io.IOException
        Parameters:
        fileChannelInputStream - the FileChannel inputstream from which to update
        start - the position to start
        chunkSize - the chunksize to use
        limit - if less than 0, means all
        Returns:
        this
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - fileChannelIinputStream null, start < 0, chunksize < 1
      • getDigestInputStream

        public java.io.InputStream getDigestInputStream​(java.io.InputStream inputStream)
        Will update the Digest while the returned InputStream will be read
        Parameters:
        inputStream - from which the data to digest will be done
        Returns:
        the new InputStream to use instead of the given one as parameter
      • getDigestOutputStream

        public java.io.OutputStream getDigestOutputStream​(java.io.OutputStream outputStream)
        Will update the Digest while the returned OutputStream will be read
        Parameters:
        outputStream - to which the data to digest will be written
        Returns:
        the new OutputStream to use instead of the given one as parameter
      • reset

        public final Digest reset()
        Reset the DigestLight
        Returns:
        this
      • digest

        public final byte[] digest()
        Returns:
        the digest
      • digestHex

        public final java.lang.String digestHex()
        Returns:
        the digest in Base16 format
      • digest64

        public final java.lang.String digest64()
        Returns:
        the digest in Base64 format
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equalsWithType

        public final boolean equalsWithType​(java.lang.String digest,
                                            DigestType algo)
        Parameters:
        digest - the digest to compare to
        algo - the associated algorithm
        Returns:
        True if the 2 digests are of the same type and same value
      • equalsWithType

        public final boolean equalsWithType​(byte[] digest,
                                            DigestType algo)
        Parameters:
        digest - the digest in byte to use
        algo - the associated algorithm
        Returns:
        True if the 2 digests are of the same type and same value
      • digest

        public static final Digest digest​(java.io.InputStream in,
                                          DigestType algo)
                                   throws java.io.IOException
        Parameters:
        in - the inputstream from which the digest will be computed
        algo - the algorithm to use
        Returns:
        the digest for this inputStream
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - in or algo null
      • digest

        public static final Digest digest​(java.io.File in,
                                          DigestType algo)
                                   throws java.io.IOException
        Parameters:
        in - the file from which the digest will be computed
        algo - the algorithm to use
        Returns:
        the digest for this File
        Throws:
        java.io.IOException - if any IO error occurs
        java.lang.IllegalArgumentException - in or algo null