Package java.security
Class DigestInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.security.DigestInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
public class DigestInputStream extends FilterInputStream
DigestInputStream is a FilterInputStream which 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.FilterInputStream
in -
Constructor Summary
Constructors Constructor Description DigestInputStream(InputStream stream, MessageDigest digest)Constructs a new instance of thisDigestInputStream, using the givenstreamand thedigest. -
Method Summary
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).intread()Reads the next byte and returns it as anint.intread(byte[] buffer, int byteOffset, int byteCount)Reads up tobyteCountbytes intobuffer, starting atbyteOffset.voidsetMessageDigest(MessageDigest digest)Sets the message digest which this stream will use.StringtoString()Returns a string containing a concise, human-readable description of thisDigestInputStreamincluding the digest.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skipMethods inherited from class java.io.InputStream
read
-
Field Details
-
digest
The message digest for this stream.
-
-
Constructor Details
-
DigestInputStream
Constructs a new instance of thisDigestInputStream, using the givenstreamand thedigest.Warning: passing a null source creates an invalid
DigestInputStream. All operations on such a stream will fail.- Parameters:
stream- the input stream.digest- the message digest.
-
-
Method Details
-
getMessageDigest
Returns the message digest for this stream.- Returns:
- the message digest for this stream.
-
setMessageDigest
Sets the message digest which this stream will use.- Parameters:
digest- the message digest which this stream will use.
-
read
Reads the next byte and returns it as anint. Updates the digest for the byte if this function ison(boolean).This operation is blocking.
- Overrides:
readin classFilterInputStream- Returns:
- the byte which was read or -1 at end of stream.
- Throws:
IOException- if reading the source stream causes anIOException.
-
read
Reads up tobyteCountbytes intobuffer, starting atbyteOffset. Updates the digest if this function ison(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.
- Overrides:
readin classFilterInputStream- Throws:
IOException- if reading the source 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
-
toString
Returns a string containing a concise, human-readable description of thisDigestInputStreamincluding the digest.
-