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

public final Class HashingOutputStream

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

An OutputStream that maintains a hash of the data written to it.
Author
Nick Piepmeier
Since
16.0

Field Summary

Modifier and TypeField and Description
private final Hasher
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
HashingOutputStream(HashFunction hashFunction, OutputStream out)

Creates an output stream that hashes using the given HashFunction, and forwards all data written to it to the underlying OutputStream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with the stream.
public HashCode
hash()

Returns the HashCode based on the data written to this stream.

public void
write(int
the byte.
b
)

Overrides java.io.FilterOutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
bytes
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
Inherited from java.io.FilterOutputStream:
flushwrite

Field Detail

hasherback to summary
private final Hasher hasher

Constructor Detail

HashingOutputStreamback to summary
public HashingOutputStream(HashFunction hashFunction, OutputStream out)

Creates an output stream that hashes using the given HashFunction, and forwards all data written to it to the underlying OutputStream.

The OutputStream should not be written to before or after the hand-off.

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterOutputStream.close.

Closes this output stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
hashback to summary
public HashCode hash()

Returns the HashCode based on the data written to this stream. The result is unspecified if this method is called more than once on the same instance.

writeback to summary
public void write(int b) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes the specified byte to this output stream.

The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b).

Implements the abstract write method of OutputStream.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] bytes, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Parameters
bytes:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.