java.security
Class DigestInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--java.security.DigestInputStream
DigestInputStream is a class that ties an InputStream with a
MessageDigest. The Message Digest is used by the class to
update it self as bytes are read from the InputStream.
The updating to the digest depends on the on flag which is set
to true by default to tell the class to update the data
in the message digest.
Author:- Mark Benvenuto <ivymccough@worldnet.att.net>
digest
protected MessageDigest digest
The message digest for the DigestInputStream
DigestInputStream
public DigestInputStream(java.io.InputStream stream, java.security.MessageDigest digest)
Constructs a new DigestInputStream.
It associates a MessageDigest with the stream to
compute the stream as data is written.
Parameters:
getMessageDigest
public MessageDigest getMessageDigest()
Returns the MessageDigest associated with this DigestInputStream
Returns:
- The MessageDigest used to hash this stream
on
public void on(boolean on)
Sets the flag specifing if this DigestInputStream updates the
digest in the write() methods. The default is on;
Parameters:
read
public int read()
Reads a byte from the input stream and updates the digest.
This method reads the underlying input stream and if the
on flag is true then updates the message digest.
Returns:
- Returns a byte from the input stream, -1 is returned to indicate that
the end of stream was reached before this read call
Throws:
IOException
- if an IO error occurs in the underlying input stream,
this error is thrown
read
public int read(byte[] , int off, int len)
Reads bytes from the input stream and updates the digest.
This method reads the underlying input stream and if the
on flag is true then updates the message digest.
Parameters:
Returns:
- Returns count of bytes read, -1 is returned to indicate that
the end of stream was reached before this read call
Throws:
IOException
- if an IO error occurs in the underlying input stream,
this error is thrown
setMessageDigest
public void setMessageDigest(java.security.MessageDigest digest)
Sets the current MessageDigest to current parameter
Parameters:
toString
public String toString()
Converts the input stream and underlying message digest to a string.
Returns:
- A string representing the input stream and message digest.