# DigestInputStream

public class **DigestInputStream** extends [FilterInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html)  
A transparent stream that updates the associated message digest using
the bits going through the stream.

To complete the message digest computation, call one of the
`digest` methods on the associated message
digest after your calls to one of this digest input stream's
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#read()` methods.

It is possible to turn this stream on or off (see
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#on(boolean)`). When it is on, a call to one of the
`read` methods
results in an update on the message digest. But when it is off,
the message digest is not updated. The default is for the stream
to be on.

Note that digest objects can compute only one digest (see
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html`),
so that in order to compute intermediate digests, a caller should
retain a handle onto the digest object, and clone it for each
digest to be computed, leaving the orginal digest untouched.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html`

### Field Summary

|---|---|---|
| protected [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) | [digest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#digest) | The message digest associated with this stream. |

### Inherited Field Summary

From class [java.io.FilterInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html)

|---|---|---|
| protected [InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) | [in](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#in) | The input stream to be filtered. |

### Public Constructor Summary

|---|---|
|   | [DigestInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#DigestInputStream(java.io.InputStream,%20java.security.MessageDigest))([InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) stream, [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) digest) Creates a digest input stream, using the specified input stream and message digest. |

### Public Method Summary

|---|---|
| [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) | [getMessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#getMessageDigest())() Returns the message digest associated with this stream. |
| void | [on](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#on(boolean))(boolean on) Turns the digest function on or off. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#read())() Reads a byte, and updates the message digest (if the digest function is on). |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#read(byte[],%20int,%20int))(byte\[\] b, int off, int len) Reads into a byte array, and updates the message digest (if the digest function is on). |
| void | [setMessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#setMessageDigest(java.security.MessageDigest))([MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) digest) Associates the specified message digest with this stream. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#toString())() Prints a string representation of this digest input stream and its associated message digest object. |

### Inherited Method Summary

From class [java.io.FilterInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html)

|---|---|
| int | [available](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#available())() Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#close())() Closes this input stream and releases any system resources associated with the stream. |
| synchronized void | [mark](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#mark(int))(int readlimit) Marks the current position in this input stream. |
| boolean | [markSupported](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#markSupported())() Tests if this input stream supports the `mark` and `reset` methods. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#read())() Reads the next byte of data from this input stream. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#read(byte[],%20int,%20int))(byte\[\] b, int off, int len) Reads up to `len` bytes of data from this input stream into an array of bytes. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#read(byte[]))(byte\[\] b) Reads up to `byte.length` bytes of data from this input stream into an array of bytes. |
| synchronized void | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#reset())() Repositions this stream to the position at the time the `mark` method was last called on this input stream. |
| long | [skip](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterInputStream.html#skip(long))(long n) Skips over and discards `n` bytes of data from the input stream. |

From class [java.io.InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html)

|---|---|
| int | [available](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#available())() Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. |
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#close())() Closes this input stream and releases any system resources associated with the stream. |
| synchronized void | [mark](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#mark(int))(int readlimit) Marks the current position in this input stream. |
| boolean | [markSupported](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#markSupported())() Tests if this input stream supports the `mark` and `reset` methods. |
| abstract int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#read())() Reads the next byte of data from the input stream. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#read(byte[],%20int,%20int))(byte\[\] b, int off, int len) Reads up to `len` bytes of data from the input stream into an array of bytes. |
| int | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#read(byte[]))(byte\[\] b) Reads some number of bytes from the input stream and stores them into the buffer array `b`. |
| synchronized void | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#reset())() Repositions this stream to the position at the time the `mark` method was last called on this input stream. |
| long | [skip](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html#skip(long))(long n) Skips over and discards `n` bytes of data from this input stream. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Fields

#### protected [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html)
**digest**

The message digest associated with this stream.

## Public Constructors

#### public
**DigestInputStream**
([InputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStream.html) stream, [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) digest)

Creates a digest input stream, using the specified input stream
and message digest.

##### Parameters

| stream | the input stream. |
| digest | the message digest to associate with this stream. |
|---|---|

## Public Methods

#### public [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html)
**getMessageDigest**
()

Returns the message digest associated with this stream.

##### Returns

- the message digest associated with this stream.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#setMessageDigest(java.security.MessageDigest)`

#### public void
**on**
(boolean on)

Turns the digest function on or off. The default is on. When
it is on, a call to one of the `read` methods results in an
update on the message digest. But when it is off, the message
digest is not updated.

##### Parameters

| on | true to turn the digest function on, false to turn it off. |
|---|---|

#### public int
**read**
()

Reads a byte, and updates the message digest (if the digest
function is on). That is, this method reads a byte from the
input stream, blocking until the byte is actually read. If the
digest function is on (see `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#on(boolean)`), this method
will then call `update` on the message digest associated
with this stream, passing it the byte read.

##### Returns

- the byte read.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html#update(byte)`

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

Reads into a byte array, and updates the message digest (if the
digest function is on). That is, this method reads up to
`len` bytes from the input stream into the array
`b`, starting at offset `off`. This method
blocks until the data is actually
read. If the digest function is on (see
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#on(boolean)`), this method will then call `update`
on the message digest associated with this stream, passing it
the data.

##### Parameters

| b | the array into which the data is read. |
| off | the starting offset into `b` of where the data should be placed. |
| len | the maximum number of bytes to be read from the input stream into b, starting at offset `off`. |
|---|---|

##### Returns

- the actual number of bytes read. This is less than `len` if the end of the stream is reached prior to reading `len` bytes. -1 is returned if no bytes were read because the end of the stream had already been reached when the call was made.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html#update(byte[],%20int,%20int)`

#### public void
**setMessageDigest**
([MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) digest)

Associates the specified message digest with this stream.

##### Parameters

| digest | the message digest to be associated with this stream. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.html#getMessageDigest()`

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Prints a string representation of this digest input stream and
its associated message digest object.

##### Returns

- a printable representation of this object.