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
DigestOutputStreamis aFilterOutputStreamwhich 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
All Methods Instance Methods Concrete Methods 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, flush
-
Methods inherited from class java.io.OutputStream
write
-
-
-
-
Field Detail
-
digest
protected MessageDigest digest
The message digest for this stream.
-
-
Constructor Detail
-
DigestOutputStream
public DigestOutputStream(OutputStream stream, MessageDigest digest)
Constructs a new instance of thisDigestOutputStream, using the givenstreamand thedigest.- Parameters:
stream- the output stream.digest- the message digest.
-
-
Method Detail
-
getMessageDigest
public MessageDigest getMessageDigest()
Returns the message digest for this stream.- Returns:
- the message digest for this stream.
-
setMessageDigest
public void setMessageDigest(MessageDigest digest)
Sets the message digest which this stream will use.- Parameters:
digest- the message digest which this stream will use.
-
write
public void write(int b) throws IOExceptionWrites 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
public void write(byte[] b, int off, int len) throws IOExceptionWriteslenbytes 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
-
-