Class HashingInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.google.common.hash.HashingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
An
InputStream
that maintains a hash of the data read from it.- Since:
- 16.0
- Author:
- Qian Huang
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionHashingInputStream
(HashFunction hashFunction, InputStream in) Creates an input stream that hashes using the givenHashFunction
and delegates all data read from it to the underlyingInputStream
. -
Method Summary
Modifier and TypeMethodDescriptionhash()
Returns theHashCode
based on the data read from this stream.void
mark
(int readlimit) mark() is not supported for HashingInputStreamboolean
mark() is not supported for HashingInputStreamint
read()
Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.int
read
(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.void
reset()
reset() is not supported for HashingInputStream.Methods inherited from class java.io.FilterInputStream
available, close, read, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
HashingInputStream
Creates an input stream that hashes using the givenHashFunction
and delegates all data read from it to the underlyingInputStream
.The
InputStream
should not be read from before or after the hand-off.
-
-
Method Details
-
read
Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
markSupported
mark() is not supported for HashingInputStream- Overrides:
markSupported
in classFilterInputStream
- Returns:
false
always
-
mark
mark() is not supported for HashingInputStream- Overrides:
mark
in classFilterInputStream
-
reset
reset() is not supported for HashingInputStream.- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
- this operation is not supported
-
hash
-