Top Description Fields Constructors Methods
com.google.common.hash

public final Class HashingInputStream

extends FilterInputStream
Class Inheritance
Annotations
@Beta
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

An InputStream that maintains a hash of the data read from it.
Author
Qian Huang
Since
16.0

Field Summary

Modifier and TypeField and Description
private final Hasher
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
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.

Method Summary

Modifier and TypeMethod and Description
public HashCode
hash()

Returns the HashCode based on the data read from this stream.

public void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
readlimit
)

Overrides java.io.FilterInputStream.mark.

mark() is not supported for HashingInputStream
public boolean

Returns:

false always
markSupported
()

Overrides java.io.FilterInputStream.markSupported.

mark() is not supported for HashingInputStream
public int
read()

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.
public int
read(byte[]
the buffer into which the data is read.
bytes
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.FilterInputStream.read.

Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.
public void
reset()

Overrides java.io.FilterInputStream.reset.

reset() is not supported for HashingInputStream.
Inherited from java.io.FilterInputStream:
availableclosereadskip

Field Detail

hasherback to summary
private final Hasher hasher

Constructor Detail

HashingInputStreamback to summary
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 Detail

hashback to summary
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.

markback to summary
public void mark(int readlimit)

Overrides java.io.FilterInputStream.mark.

mark() is not supported for HashingInputStream

Parameters
readlimit:int

Doc from java.io.FilterInputStream.mark.

the maximum limit of bytes that can be read before the mark position becomes invalid.

Annotations
@Override
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

mark() is not supported for HashingInputStream

Returns:boolean

false always

Annotations
@Override
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Reads the next byte of data from the underlying input stream and updates the hasher with the byte read.

Returns:int

Doc from java.io.FilterInputStream.read.

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
@CanIgnoreReturnValue
Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

readback to summary
public int read(byte[] bytes, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read.

Parameters
bytes:byte[]

Doc from java.io.FilterInputStream.read.

the buffer into which the data is read.

off:int

Doc from java.io.FilterInputStream.read.

the start offset in array b at which the data is written.

len:int

Doc from java.io.FilterInputStream.read.

the maximum number of bytes to read.

Returns:int

Doc from java.io.FilterInputStream.read.

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
@CanIgnoreReturnValue
Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

resetback to summary
public void reset() throws IOException

Overrides java.io.FilterInputStream.reset.

reset() is not supported for HashingInputStream.

Annotations
@Override
Exceptions
IOException:
this operation is not supported