# DigestOutputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary: [Fields](https://developer.android.com/reference/java/security/DigestOutputStream#lfields) \| [Inherited Fields](https://developer.android.com/reference/java/security/DigestOutputStream#inhfields) \| [Ctors](https://developer.android.com/reference/java/security/DigestOutputStream#pubctors) \| [Methods](https://developer.android.com/reference/java/security/DigestOutputStream#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/DigestOutputStream#inhmethods)  

# DigestOutputStream


`
public


class
DigestOutputStream
`


`


`

`


`

`

extends `[FilterOutputStream](https://developer.android.com/reference/java/io/FilterOutputStream)`


`

`


`

|---|---|---|----------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||||
| ↳ | [java.io.OutputStream](https://developer.android.com/reference/java/io/OutputStream) |||
|   | ↳ | [java.io.FilterOutputStream](https://developer.android.com/reference/java/io/FilterOutputStream) ||
|   |   | ↳ | java.security.DigestOutputStream |

<br />

*** ** * ** ***

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
[write](https://developer.android.com/reference/java/security/DigestOutputStream#write(int)) methods.

It is possible to turn this stream on or off (see
[on](https://developer.android.com/reference/java/security/DigestOutputStream#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:**

- [MessageDigest](https://developer.android.com/reference/java/security/MessageDigest)
- [DigestInputStream](https://developer.android.com/reference/java/security/DigestInputStream)

## Summary

|                                                                                                                  ### Fields                                                                                                                  ||
|---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| ` protected `[MessageDigest](https://developer.android.com/reference/java/security/MessageDigest) | [digest](https://developer.android.com/reference/java/security/DigestOutputStream#digest) The message digest associated with this stream. |

|                                                                                                                                                                                                                                                                       ### Inherited fields                                                                                                                                                                                                                                                                        |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From class [java.io.FilterOutputStream](https://developer.android.com/reference/java/io/FilterOutputStream) |-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------| | ` protected `[OutputStream](https://developer.android.com/reference/java/io/OutputStream) | [out](https://developer.android.com/reference/java/io/FilterOutputStream#out) The underlying output stream to be filtered. | |

|                                                                                                                                                                                                                   ### Public constructors                                                                                                                                                                                                                   ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[DigestOutputStream](https://developer.android.com/reference/java/security/DigestOutputStream#DigestOutputStream(java.io.OutputStream,%20java.security.MessageDigest))`(`[OutputStream](https://developer.android.com/reference/java/io/OutputStream)` stream, `[MessageDigest](https://developer.android.com/reference/java/security/MessageDigest)` digest) ` Creates a digest output stream, using the specified output stream and message digest. |

|                                                                                                                                                                                         ### Public methods                                                                                                                                                                                         ||
|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[MessageDigest](https://developer.android.com/reference/java/security/MessageDigest) | ` `[getMessageDigest](https://developer.android.com/reference/java/security/DigestOutputStream#getMessageDigest())`() ` Returns the message digest associated with this stream.                                                                                                                           |
| ` void`                                                                                 | ` `[on](https://developer.android.com/reference/java/security/DigestOutputStream#on(boolean))`(boolean on) ` Turns the digest function on or off.                                                                                                                                                         |
| ` void`                                                                                 | ` `[setMessageDigest](https://developer.android.com/reference/java/security/DigestOutputStream#setMessageDigest(java.security.MessageDigest))`(`[MessageDigest](https://developer.android.com/reference/java/security/MessageDigest)` digest) ` Associates the specified message digest with this stream. |
| ` `[String](https://developer.android.com/reference/java/lang/String)                   | ` `[toString](https://developer.android.com/reference/java/security/DigestOutputStream#toString())`() ` Prints a string representation of this digest output stream and its associated message digest object.                                                                                             |
| ` void`                                                                                 | ` `[write](https://developer.android.com/reference/java/security/DigestOutputStream#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://developer.android.com/reference/java/security/DigestOutputStream#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 methods |
|-----------------------|---|
| From class ` `[java.io.FilterOutputStream](https://developer.android.com/reference/java/io/FilterOutputStream)` ` |---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void` | ` `[close](https://developer.android.com/reference/java/io/FilterOutputStream#close())`() ` Closes this output stream and releases any system resources associated with the stream.                                                          | | ` void` | ` `[flush](https://developer.android.com/reference/java/io/FilterOutputStream#flush())`() ` Flushes this output stream and forces any buffered output bytes to be written out to the stream.                                                 | | ` void` | ` `[write](https://developer.android.com/reference/java/io/FilterOutputStream#write(byte[]))`(byte[] b) ` Writes `b.length` bytes to this output stream.                                                                                     | | ` void` | ` `[write](https://developer.android.com/reference/java/io/FilterOutputStream#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://developer.android.com/reference/java/io/FilterOutputStream#write(int))`(int b) ` Writes the specified `byte` to this output stream.                                                                                       | ||
| From class ` `[java.io.OutputStream](https://developer.android.com/reference/java/io/OutputStream)` ` |----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void`                                                                                | ` `[close](https://developer.android.com/reference/java/io/OutputStream#close())`() ` Closes this output stream and releases any system resources associated with this stream.                                                       | | ` void`                                                                                | ` `[flush](https://developer.android.com/reference/java/io/OutputStream#flush())`() ` Flushes this output stream and forces any buffered output bytes to be written out.                                                             | | ` static `[OutputStream](https://developer.android.com/reference/java/io/OutputStream) | ` `[nullOutputStream](https://developer.android.com/reference/java/io/OutputStream#nullOutputStream())`() ` Returns a new `OutputStream` which discards all bytes.                                                                   | | ` void`                                                                                | ` `[write](https://developer.android.com/reference/java/io/OutputStream#write(byte[]))`(byte[] b) ` Writes `b.length` bytes from the specified byte array to this output stream.                                                     | | ` void`                                                                                | ` `[write](https://developer.android.com/reference/java/io/OutputStream#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://developer.android.com/reference/java/io/OutputStream#write(int))`(int b) ` Writes the specified byte to this output stream.                                                                                       | ||
| From class ` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                        | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                             | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                            | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`.                                                                                                                                                 | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                   | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                              | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                           | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                              | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.                                                                                             | ||
| From interface ` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| From interface ` `[java.io.Flushable](https://developer.android.com/reference/java/io/Flushable)` ` |------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[flush](https://developer.android.com/reference/java/io/Flushable#flush())`() ` Flushes this stream by writing any buffered output to the underlying stream. | ||
| From interface ` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Fields

### digest

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected MessageDigest digest
```

The message digest associated with this stream.

<br />

## Public constructors

### DigestOutputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public DigestOutputStream (OutputStream stream, 
                MessageDigest digest)
```

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

<br />

|                                     Parameters                                      ||
|----------|---------------------------------------------------------------------------|
| `stream` | `OutputStream`: the output stream. <br />                                 |
| `digest` | `MessageDigest`: the message digest to associate with this stream. <br /> |

## Public methods

### getMessageDigest

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MessageDigest getMessageDigest ()
```

Returns the message digest associated with this stream.

<br />

|                                                                   Returns                                                                    ||
|--------------------------------------------------------------------------------------|--------------------------------------------------------|
| [MessageDigest](https://developer.android.com/reference/java/security/MessageDigest) | the message digest associated with this stream. <br /> |

**See also:**

- [setMessageDigest(java.security.MessageDigest)](https://developer.android.com/reference/java/security/DigestOutputStream#setMessageDigest(java.security.MessageDigest))  

### on

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.

<br />

|                                     Parameters                                     ||
|------|------------------------------------------------------------------------------|
| `on` | `boolean`: true to turn the digest function on, false to turn it off. <br /> |

### setMessageDigest

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setMessageDigest (MessageDigest digest)
```

Associates the specified message digest with this stream.

<br />

|                                       Parameters                                        ||
|----------|-------------------------------------------------------------------------------|
| `digest` | `MessageDigest`: the message digest to be associated with this stream. <br /> |

**See also:**

- [getMessageDigest()](https://developer.android.com/reference/java/security/DigestOutputStream#getMessageDigest())  

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

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

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |

### write

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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
[on](https://developer.android.com/reference/java/security/DigestOutputStream#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.

<br />

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

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

**See also:**

- [MessageDigest.update(byte[], int, int)](https://developer.android.com/reference/java/security/MessageDigest#update(byte[],%20int,%20int))  

### write

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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 [on](https://developer.android.com/reference/java/security/DigestOutputStream#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.

<br />

|                                      Parameters                                       ||
|-----|----------------------------------------------------------------------------------|
| `b` | `int`: the byte to be used for updating and writing to the output stream. <br /> |

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if an I/O error occurs. |

**See also:**

- [MessageDigest.update(byte)](https://developer.android.com/reference/java/security/MessageDigest#update(byte))