Package java.security
Class DigestOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.security.DigestOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class DigestOutputStream extends FilterOutputStream
DigestOutputStream is a FilterOutputStream which maintains an
associated message digest.-
Field Summary
Fields Modifier and Type Field Description protected MessageDigestdigestThe message digest for this stream.Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors Constructor Description DigestOutputStream(OutputStream stream, MessageDigest digest)Constructs a new instance of thisDigestOutputStream, using the givenstreamand thedigest. -
Method Summary
Modifier and Type Method Description MessageDigestgetMessageDigest()Returns the message digest for this stream.voidon(boolean on)Enables or disables the digest function (default is on).voidsetMessageDigest(MessageDigest digest)Sets the message digest which this stream will use.StringtoString()Returns a string containing a concise, human-readable description of thisDigestOutputStreamincluding the digest.voidwrite(byte[] b, int off, int len)Writeslenbytes into the stream, starting from the specified offset.voidwrite(int b)Writes the specifiedintto the stream.Methods inherited from class java.io.FilterOutputStream
close, flushMethods inherited from class java.io.OutputStream
write
-
Field Details
-
digest
The message digest for this stream.
-
-
Constructor Details
-
DigestOutputStream
Constructs a new instance of thisDigestOutputStream, using the givenstreamand thedigest.- Parameters:
stream- the output stream.digest- the message digest.
-
-
Method Details
-
getMessageDigest
Returns the message digest for this stream.- Returns:
- the message digest for this stream.
-
setMessageDigest
Sets the message digest which this stream will use.- Parameters:
digest- the message digest which this stream will use.
-
write
Writes the specifiedintto the stream. Updates the digest if this function ison(boolean).- Overrides:
writein classFilterOutputStream- Parameters:
b- the byte to be written.- Throws:
IOException- if writing to the stream causes aIOException
-
write
Writeslenbytes into the stream, starting from the specified offset. Updates the digest if this function ison(boolean).- Overrides:
writein classFilterOutputStream- Parameters:
b- the buffer to write to.off- the index of the first byte inbto write.len- the number of bytes inbto write.- Throws:
IOException- if writing to the stream causes anIOException.
-
on
public void on(boolean on)Enables or disables the digest function (default is on).- Parameters:
on-trueif the digest should be computed,falseotherwise.- See Also:
MessageDigest
-
toString
Returns a string containing a concise, human-readable description of thisDigestOutputStreamincluding the digest.
-