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:
- Nick Piepmeier
 
- 
- 
Field Summary- 
Fields inherited from class java.io.FilterOutputStreamout
 
- 
 - 
Constructor SummaryConstructors 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 SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this output stream and releases any system resources associated with the stream.HashCodehash()Returns theHashCodebased on the data written to this stream.voidwrite(byte[] bytes, int off, int len)Writeslenbytes from the specifiedbytearray starting at offsetoffto this output stream.voidwrite(int b)Writes the specifiedbyteto this output stream.- 
Methods inherited from class java.io.FilterOutputStreamflush, write
 - 
Methods inherited from class java.io.OutputStreamnullOutputStream
 
- 
 
- 
- 
- 
Constructor Detail- 
HashingOutputStreampublic 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- 
writepublic void write(int b) throws IOException Description copied from class:java.io.FilterOutputStreamWrites the specifiedbyteto this output stream.The writemethod ofFilterOutputStreamcalls thewritemethod of its underlying output stream, that is, it performsout.write(b).Implements the abstract writemethod ofOutputStream.- Overrides:
- writein class- FilterOutputStream
- Parameters:
- b- the- byte.
- Throws:
- IOException- if an I/O error occurs.
 
 - 
writepublic void write(byte[] bytes, int off, int len) throws IOException Description copied from class:java.io.FilterOutputStreamWriteslenbytes from the specifiedbytearray starting at offsetoffto this output stream.The writemethod ofFilterOutputStreamcalls thewritemethod of one argument on eachbyteto output.Note that this method does not call the writemethod of its underlying output stream with the same arguments. Subclasses ofFilterOutputStreamshould provide a more efficient implementation of this method.- Overrides:
- writein class- FilterOutputStream
- Parameters:
- bytes- the data.
- off- the start offset in the data.
- len- the number of bytes to write.
- Throws:
- IOException- if an I/O error occurs.
- See Also:
- FilterOutputStream.write(int)
 
 - 
hashpublic 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.
 - 
closepublic void close() throws IOException Description copied from class:java.io.FilterOutputStreamCloses this output stream and releases any system resources associated with the stream.When not already closed, the closemethod ofFilterOutputStreamcalls itsflushmethod, and then calls theclosemethod of its underlying output stream.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- FilterOutputStream
- Throws:
- IOException- if an I/O error occurs.
- See Also:
- FilterOutputStream.flush(),- FilterOutputStream.out
 
 
- 
 
-