Class HashingInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.google.common.hash.HashingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class HashingInputStream extends FilterInputStream
An InputStream that maintains a hash of the data read from it.
Since:
16.0
  • Field Details

    • hasher

      private final Hasher hasher
  • Constructor Details

    • HashingInputStream

      public HashingInputStream(HashFunction hashFunction, InputStream in)
      Creates an input stream that hashes using the given HashFunction and delegates all data read from it to the underlying InputStream.

      The InputStream should not be read from before or after the hand-off.

  • Method Details

    • read

      public int read() throws IOException
      Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] bytes, int off, int len) throws IOException
      Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • markSupported

      public boolean markSupported()
      mark() is not supported for HashingInputStream
      Overrides:
      markSupported in class FilterInputStream
      Returns:
      false always
    • mark

      public void mark(int readlimit)
      mark() is not supported for HashingInputStream
      Overrides:
      mark in class FilterInputStream
    • reset

      public void reset() throws IOException
      reset() is not supported for HashingInputStream.
      Overrides:
      reset in class FilterInputStream
      Throws:
      IOException - this operation is not supported
    • hash

      public HashCode hash()
      Returns the HashCode based on the data read from this stream. The result is unspecified if this method is called more than once on the same instance.