Skip to content

Most visited

Recently visited

navigation
Added in API level 1

DigestInputStream

public class DigestInputStream
extends FilterInputStream

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


DigestInputStream is a FilterInputStream which maintains an associated message digest.

Summary

Fields

protected MessageDigest digest

The message digest for this stream.

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.

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

digest

Added in API level 1
MessageDigest digest

The message digest for this stream.

Public constructors

DigestInputStream

Added in API level 1
DigestInputStream (InputStream stream, 
                MessageDigest digest)

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 InputStream: the input stream.
digest MessageDigest: the message digest.

Public methods

getMessageDigest

Added in API level 1
MessageDigest getMessageDigest ()

Returns the message digest for this stream.

Returns
MessageDigest the message digest for this stream.

on

Added in API level 1
void on (boolean on)

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

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

See also:

read

Added in API level 1
int read ()

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
int the byte which was read or -1 at end of stream.
Throws
IOException if reading the source stream causes an IOException.

read

Added in API level 1
int read (byte[] buffer, 
                int byteOffset, 
                int byteCount)

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.

Parameters
buffer byte
byteOffset int
byteCount int
Returns
int
Throws
IOException if reading the source stream causes an IOException

setMessageDigest

Added in API level 1
void setMessageDigest (MessageDigest digest)

Sets the message digest which this stream will use.

Parameters
digest MessageDigest: the message digest which this stream will use.

toString

Added in API level 1
String toString ()

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

Returns
String a printable representation for this DigestInputStream.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.