public class DigestInputStream extends FilterInputStream
DigestInputStream is a FilterInputStream which maintains an
associated message digest.| Modifier and Type | Field and Description |
|---|---|
protected MessageDigest |
digest
The message digest for this stream.
|
in| Constructor and Description |
|---|
DigestInputStream(InputStream stream,
MessageDigest digest)
Constructs a new instance of this
DigestInputStream, 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).
|
int |
read()
Reads the next byte and returns it as an
int. |
int |
read(byte[] buffer,
int byteOffset,
int byteCount)
Reads up to
byteCount bytes into buffer, starting at
byteOffset. |
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
DigestInputStream including the digest. |
available, close, mark, markSupported, reset, skipnullInputStream, read, readAllBytes, readNBytes, readNBytes, transferToprotected MessageDigest digest
public DigestInputStream(InputStream stream, MessageDigest digest)
DigestInputStream, using the
given stream and the digest.
Warning: passing a null source creates an invalid
DigestInputStream. All operations on such a stream will fail.
stream - the input stream.digest - the message digest.public MessageDigest getMessageDigest()
public void setMessageDigest(MessageDigest digest)
digest - the message digest which this stream will use.public int read()
throws IOException
int. Updates the digest
for the byte if this function is on(boolean).
This operation is blocking.
read in class FilterInputStreamIOException - if reading the source stream causes an IOException.public int read(byte[] buffer,
int byteOffset,
int byteCount)
throws IOException
byteCount bytes into buffer, starting at
byteOffset. Updates the digest if this function is
on(boolean).
This operation is blocking.
Returns the number of bytes actually read or -1 if the end of the filtered stream has been reached while reading.
read in class FilterInputStreamIOException - if reading the source stream causes an IOExceptionpublic void on(boolean on)
on - true if the digest should be computed, false
otherwise.MessageDigest