public class

DigestInputStream

extends FilterInputStream
java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.security.DigestInputStream

Class Overview

DigestInputStream is a FilterInputStream which maintains an associated message digest.

Summary

Fields
protected MessageDigest digest The message digest for this stream.
[Expand]
Inherited Fields
From class java.io.FilterInputStream
Public Constructors
DigestInputStream(InputStream stream, MessageDigest digest)
Constructs a new instance of this DigestInputStream, using the given stream and the digest.
Public Methods
MessageDigest getMessageDigest()
Returns the message digest for this stream.
void on(boolean on)
Enables or disables the digest function (default is on).
int read(byte[] b, int off, int len)
Reads len bytes into the specified byte[], starting from the specified offset.
int read()
Reads the next byte and returns it as an int.
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.
[Expand]
Inherited Methods
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable

Fields

protected MessageDigest digest

Since: API Level 1

The message digest for this stream.

Public Constructors

public DigestInputStream (InputStream stream, MessageDigest digest)

Since: API Level 1

Constructs a new instance of this DigestInputStream, using the given stream and the digest.

Parameters
stream the input stream.
digest the message digest.

Public Methods

public MessageDigest getMessageDigest ()

Since: API Level 1

Returns the message digest for this stream.

Returns
  • the message digest for this stream.

public void on (boolean on)

Since: API Level 1

Enables or disables the digest function (default is on).

Parameters
on true if the digest should be computed, false otherwise.

public int read (byte[] b, int off, int len)

Since: API Level 1

Reads len bytes into the specified byte[], starting from the specified offset. Updates the digest if this function is on(boolean).

This operation is blocking.

Parameters
b the byte array in which to store the bytes
off the initial position in b to store the bytes read from this stream
len the maximum number of bytes to store in b
Returns
  • the number of bytes actually read or -1 if the end of the filtered stream has been reached while reading
Throws
IOException if reading the source stream causes an IOException

public int read ()

Since: API Level 1

Reads the next byte and returns it as an int. Updates the digest for the byte if this function is on(boolean).

This operation is blocking.

Returns
  • the byte which was read or -1 at end of stream.
Throws
IOException if reading the source stream causes an IOException.

public void setMessageDigest (MessageDigest digest)

Since: API Level 1

Sets the message digest which this stream will use.

Parameters
digest the message digest which this stream will use.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this DigestInputStream including the digest.

Returns
  • a printable representation for this DigestInputStream.