Methods Summary |
---|
public java.security.MessageDigest | getMessageDigest()Returns the message digest for this stream.
return digest;
|
public void | on(boolean on)Enables or disables the digest function (default is on).
isOn = on;
|
public int | read()Reads the next byte and returns it as an {@code int}. Updates the digest
for the byte if this function is {@link #on(boolean)}.
This operation is blocking.
// read the next byte
int byteRead = in.read();
// update digest only if
// - digest functionality is on
// - eos has not been reached
if (isOn && (byteRead != -1)) {
digest.update((byte)byteRead);
}
// return byte read
return byteRead;
|
public int | read(byte[] b, int off, int len)Reads {@code len} bytes into the specified {@code byte[]}, starting from
the specified offset. Updates the digest if this function is
{@link #on(boolean)}.
This operation is blocking.
// read next up to len bytes
int bytesRead = in.read(b, off, len);
// update digest only if
// - digest functionality is on
// - eos has not been reached
if (isOn && (bytesRead != -1)) {
digest.update(b, off, bytesRead);
}
// return number of bytes read
return bytesRead;
|
public void | setMessageDigest(java.security.MessageDigest digest)Sets the message digest which this stream will use.
this.digest = digest;
|
public java.lang.String | toString()Returns a string containing a concise, human-readable description of this
{@code DigestInputStream} including the digest.
return super.toString() + ", " + digest.toString() + //$NON-NLS-1$
(isOn ? ", is on" : ", is off"); //$NON-NLS-1$ //$NON-NLS-2$
|