Package com.google.common.hash
Class HashingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.google.common.hash.HashingOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
@Beta public final class HashingOutputStream extends FilterOutputStream
AnOutputStreamthat maintains a hash of the data written to it.- Since:
- 16.0
- Author:
- Zoe Piepmeier
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description HashingOutputStream(HashFunction hashFunction, OutputStream out)Creates an output stream that hashes using the givenHashFunction, and forwards all data written to it to the underlyingOutputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()HashCodehash()Returns theHashCodebased on the data written to this stream.voidwrite(byte[] bytes, int off, int len)voidwrite(int b)-
Methods inherited from class java.io.FilterOutputStream
flush, write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
HashingOutputStream
public HashingOutputStream(HashFunction hashFunction, OutputStream out)
Creates an output stream that hashes using the givenHashFunction, and forwards all data written to it to the underlyingOutputStream.The
OutputStreamshould not be written to before or after the hand-off.
-
-
Method Detail
-
write
public void write(int b) throws IOException
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
public void write(byte[] bytes, int off, int len) throws IOException
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
hash
public HashCode hash()
Returns theHashCodebased on the data written to this stream. The result is unspecified if this method is called more than once on the same instance.
-
close
public void close() throws IOException
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
-