Package com.google.common.hash
Class HashingInputStream
- java.lang.Object
- 
- java.io.InputStream
- 
- java.io.FilterInputStream
- 
- com.google.common.hash.HashingInputStream
 
 
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 @Beta public final class HashingInputStream extends FilterInputStream AnInputStreamthat maintains a hash of the data read from it.- Since:
- 16.0
- Author:
- Qian Huang
 
- 
- 
Field Summary- 
Fields inherited from class java.io.FilterInputStreamin
 
- 
 - 
Constructor SummaryConstructors Constructor Description HashingInputStream(HashFunction hashFunction, InputStream in)Creates an input stream that hashes using the givenHashFunctionand delegates all data read from it to the underlyingInputStream.
 - 
Method SummaryAll 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.- 
Methods inherited from class java.io.FilterInputStreamavailable, close, read, skip
 - 
Methods inherited from class java.io.InputStreamnullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
 
- 
 
- 
- 
- 
Constructor Detail- 
HashingInputStreampublic HashingInputStream(HashFunction hashFunction, 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 IOException Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.- Overrides:
- readin class- FilterInputStream
- Returns:
- the next byte of data, or -1if the end of the stream is reached.
- Throws:
- IOException- if an I/O error occurs.
- See Also:
- FilterInputStream.in
 
 - 
read@CanIgnoreReturnValue 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:
- readin class- FilterInputStream
- Parameters:
- bytes- the buffer into which the data is read.
- off- the start offset in the destination array- b
- len- the maximum number of bytes read.
- Returns:
- the total number of bytes read into the buffer, or
             -1if there is no more data because the end of the stream has been reached.
- Throws:
- IOException- if an I/O error occurs.
- See Also:
- FilterInputStream.in
 
 - 
markSupportedpublic boolean markSupported() mark() is not supported for HashingInputStream- Overrides:
- markSupportedin class- FilterInputStream
- Returns:
- falsealways
- See Also:
- FilterInputStream.in,- InputStream.mark(int),- InputStream.reset()
 
 - 
markpublic void mark(int readlimit) mark() is not supported for HashingInputStream- Overrides:
- markin class- FilterInputStream
- Parameters:
- readlimit- the maximum limit of bytes that can be read before the mark position becomes invalid.
- See Also:
- FilterInputStream.in,- FilterInputStream.reset()
 
 - 
resetpublic void reset() throws IOException reset() is not supported for HashingInputStream.- Overrides:
- resetin class- FilterInputStream
- Throws:
- IOException- this operation is not supported
- See Also:
- FilterInputStream.in,- FilterInputStream.mark(int)
 
 
- 
 
-