public class DigestOutputStream extends FilterOutputStream
DigestOutputStream
is a FilterOutputStream
which maintains an
associated message digest.Modifier and Type | Field and Description |
---|---|
protected MessageDigest |
digest
The message digest for this stream.
|
out
Constructor and Description |
---|
DigestOutputStream(OutputStream stream,
MessageDigest digest)
Constructs a new instance of this
DigestOutputStream , using the
given stream and the digest . |
Modifier and Type | Method and Description |
---|---|
MessageDigest |
getMessageDigest()
Returns the message digest for this stream.
|
void |
on(boolean on)
Enables or disables the digest function (default is on).
|
void |
setMessageDigest(MessageDigest digest)
Sets the message digest which this stream will use.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
DigestOutputStream including the digest. |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes into the stream, starting from the specified
offset. |
void |
write(int b)
Writes the specified
int to the stream. |
close, flush
write
protected MessageDigest digest
public DigestOutputStream(OutputStream stream, MessageDigest digest)
DigestOutputStream
, using the
given stream
and the digest
.stream
- the output stream.digest
- the message digest.public MessageDigest getMessageDigest()
public void setMessageDigest(MessageDigest digest)
digest
- the message digest which this stream will use.public void write(int b) throws IOException
int
to the stream. Updates the digest if
this function is on(boolean)
.write
in class FilterOutputStream
b
- the byte to be written.IOException
- if writing to the stream causes a IOException
public void write(byte[] b, int off, int len) throws IOException
len
bytes into the stream, starting from the specified
offset. Updates the digest if this function is on(boolean)
.write
in class FilterOutputStream
b
- the buffer to write to.off
- the index of the first byte in b
to write.len
- the number of bytes in b
to write.IOException
- if writing to the stream causes an IOException
.public void on(boolean on)
on
- true
if the digest should be computed, false
otherwise.MessageDigest