to top
Android APIs
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()
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.
[Expand]
Inherited Methods
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Fields

protected MessageDigest digest

Added in API level 1

The message digest for this stream.

Public Constructors

public DigestInputStream (InputStream stream, MessageDigest digest)

Added in API level 1

Constructs a new instance of this 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.

Parameters
stream the input stream.
digest the message digest.

Public Methods

public MessageDigest getMessageDigest ()

Added in API level 1

Returns the message digest for this stream.

Returns
  • the message digest for this stream.

public void on (boolean on)

Added in API level 1

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

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

public int read ()

Added in 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 int read (byte[] buffer, int byteOffset, int byteCount)

Added in API level 1

Reads up to 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.

Throws
IOException if reading the source stream causes an IOException

public void setMessageDigest (MessageDigest digest)

Added in 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 ()

Added in 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.