Package com.google.common.hash
Class HashingInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- com.google.common.hash.HashingInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
@Beta public final class HashingInputStream extends java.io.FilterInputStream
AnInputStreamthat maintains a hash of the data read from it.- Since:
- 16.0
- Author:
- Qian Huang
-
-
Constructor Summary
Constructors Constructor Description HashingInputStream(HashFunction hashFunction, java.io.InputStream in)Creates an input stream that hashes using the givenHashFunctionand delegates all data read from it to the underlyingInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HashCodehash()Returns theHashCodebased on the data read from this stream.voidmark(int readlimit)mark() is not supported for HashingInputStreambooleanmarkSupported()mark() is not supported for HashingInputStreamintread()Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.intread(byte[] bytes, int off, int len)Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.voidreset()reset() is not supported for HashingInputStream.
-
-
-
Constructor Detail
-
HashingInputStream
public HashingInputStream(HashFunction hashFunction, java.io.InputStream in)
Creates an input stream that hashes using the givenHashFunctionand delegates all data read from it to the underlyingInputStream.The
InputStreamshould not be read from before or after the hand-off.
-
-
Method Detail
-
read
@CanIgnoreReturnValue public int read() throws java.io.IOException
Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
@CanIgnoreReturnValue public int read(byte[] bytes, int off, int len) throws java.io.IOException
Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
mark() is not supported for HashingInputStream- Overrides:
markSupportedin classjava.io.FilterInputStream- Returns:
falsealways
-
mark
public void mark(int readlimit)
mark() is not supported for HashingInputStream- Overrides:
markin classjava.io.FilterInputStream
-
reset
public void reset() throws java.io.IOException
reset() is not supported for HashingInputStream.- Overrides:
resetin classjava.io.FilterInputStream- Throws:
java.io.IOException- this operation is not supported
-
-