Class AnvDigestInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.saidone.misc.AnvDigestInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class AnvDigestInputStream extends FilterInputStream
AnvDigestInputStream wraps another InputStream and computes a message digest while the data is read.

The digest algorithm is provided at construction time and each read operation updates the underlying MessageDigest. When the stream has been consumed the final hash value can be obtained via getHash(). This utility is typically used when a checksum or fingerprint of the streamed content is required without buffering the entire input in memory.

  • Constructor Details

    • AnvDigestInputStream

      public AnvDigestInputStream(InputStream inputStream, String algorithm) throws NoSuchAlgorithmException
      Creates a new digesting stream using the supplied algorithm.
      Parameters:
      inputStream - the underlying stream to read
      algorithm - name of the MessageDigest algorithm
      Throws:
      NoSuchAlgorithmException - if the algorithm is not available
    • AnvDigestInputStream

      public AnvDigestInputStream(InputStream inputStream)
      Creates a digesting stream that performs no hashing. This constructor is mainly useful when the same type is required but hashing is disabled.
      Parameters:
      inputStream - the underlying stream
  • Method Details