# DigestOutputStream

public class **DigestOutputStream** extends [FilterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.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 output stream's
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#write(int)` methods.

It is possible to turn this stream on or off (see
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#on(boolean)`). When it is on, a call to one of the
`write` 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.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestInputStream.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/DigestOutputStream.html#digest) | The message digest associated with this stream. |

### Inherited Field Summary

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

|---|---|---|
| protected [OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) | [out](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#out) | The underlying output stream to be filtered. |

### Public Constructor Summary

|---|---|
|   | [DigestOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#DigestOutputStream(java.io.OutputStream,%20java.security.MessageDigest))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) stream, [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) digest) Creates a digest output stream, using the specified output 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/DigestOutputStream.html#getMessageDigest())() Returns the message digest associated with this stream. |
| void | [on](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#on(boolean))(boolean on) Turns the digest function on or off. |
| void | [setMessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.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/DigestOutputStream.html#toString())() Prints a string representation of this digest output stream and its associated message digest object. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Updates the message digest (if the digest function is on) using the specified subarray, and in any case writes the subarray to the output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#write(int))(int b) Updates the message digest (if the digest function is on) using the specified byte, and in any case writes the byte to the output stream. |

### Inherited Method Summary

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

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#close())() Closes this output stream and releases any system resources associated with the stream. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#flush())() Flushes this output stream and forces any buffered output bytes to be written out to the stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#write(byte[]))(byte\[\] b) Writes `b.length` bytes to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Writes `len` bytes from the specified `byte` array starting at offset `off` to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#write(int))(int b) Writes the specified `byte` to this output stream. |

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

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#close())() Closes this output stream and releases any system resources associated with this stream. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#flush())() Flushes this output stream and forces any buffered output bytes to be written out. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[]))(byte\[\] b) Writes `b.length` bytes from the specified byte array to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Writes `len` bytes from the specified byte array starting at offset `off` to this output stream. |
| abstract void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(int))(int b) Writes the specified byte to this output 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.io.Flushable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html)

|---|---|
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html#flush())() Flushes this stream by writing any buffered output to the underlying stream. |

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
**DigestOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) stream, [MessageDigest](https://developers.google.com/j2objc/javadoc/jre/reference/java/security/MessageDigest.html) digest)

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

##### Parameters

| stream | the output 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/DigestOutputStream.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 `write` 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 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/DigestOutputStream.html#getMessageDigest()`

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

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

##### Returns

- a printable representation of this object.

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

Updates the message digest (if the digest function is on) using
the specified subarray, and in any case writes the subarray to
the output stream. That is, if the digest function is on (see
`https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#on(boolean)`), this method calls `update`
on the message digest associated with this stream, passing it
the subarray specifications. This method then writes the subarray
bytes to the output stream, blocking until the bytes are actually
written.

##### Parameters

| b | the array containing the subarray to be used for updating and writing to the output stream. |
| off | the offset into `b` of the first byte to be updated and written. |
| len | the number of bytes of data to be updated and written from `b`, starting at offset `off`. |
|---|---|

##### 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
**write**
(int b)

Updates the message digest (if the digest function is on) using
the specified byte, and in any case writes the byte
to the output stream. That is, if the digest function is on
(see `https://developers.google.com/j2objc/javadoc/jre/reference/java/security/DigestOutputStream.html#on(boolean)`), this method calls
`update` on the message digest associated with this
stream, passing it the byte `b`. This method then
writes the byte to the output stream, blocking until the byte
is actually written.

##### Parameters

| b | the byte to be used for updating and writing to the output stream. |
|---|---|

##### 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)`