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

# PipedOutputStream

` public class PipedOutputStream `   
` ` ` extends https://developer.android.com/reference/java/io/OutputStream ` ` `

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

<br />

*** ** * ** ***

A piped output stream can be connected to a piped input stream to create a communications pipe. The piped output stream is the sending end of the pipe. Typically, data is written to a `PipedOutputStream` object by one thread and data is read from the connected `PipedInputStream` by some other thread. Attempting to use both objects from a single thread is not recommended as it may deadlock the thread. The pipe is said to be *broken* if a thread that was reading data bytes from the connected piped input stream is no longer alive.
**See also:**

- `https://developer.android.com/reference/java/io/PipedInputStream`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/io/PipedOutputStream#PipedOutputStream()() ` Creates a piped output stream that is not yet connected to a piped input stream. |
| ` https://developer.android.com/reference/java/io/PipedOutputStream#PipedOutputStream(java.io.PipedInputStream)(https://developer.android.com/reference/java/io/PipedInputStream snk) ` Creates a piped output stream connected to the specified piped input stream. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/io/PipedOutputStream#close()() ` Closes this piped output stream and releases any system resources associated with this stream. |
| ` void` | ` https://developer.android.com/reference/java/io/PipedOutputStream#connect(java.io.PipedInputStream)(https://developer.android.com/reference/java/io/PipedInputStream snk) ` Connects this piped output stream to a receiver. |
| ` void` | ` https://developer.android.com/reference/java/io/PipedOutputStream#flush()() ` Flushes this output stream and forces any buffered output bytes to be written out. |
| ` void` | ` https://developer.android.com/reference/java/io/PipedOutputStream#write(byte[],%20int,%20int)(byte[] b, int off, int len) ` Writes `len` bytes from the specified byte array starting at offset `off` to this piped output stream. |
| ` void` | ` https://developer.android.com/reference/java/io/PipedOutputStream#write(int)(int b) ` Writes the specified `byte` to the piped output stream. |

### Inherited methods

From class ` https://developer.android.com/reference/java/io/OutputStream ` ` void` ` https://developer.android.com/reference/java/io/OutputStream#close()() `

Closes this output stream and releases any system resources associated with this stream.
` void` ` https://developer.android.com/reference/java/io/OutputStream#flush()() `

Flushes this output stream and forces any buffered output bytes to be written out.
` static https://developer.android.com/reference/java/io/OutputStream` ` https://developer.android.com/reference/java/io/OutputStream#nullOutputStream()() `

Returns a new `OutputStream` which discards all bytes.
` void` ` 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` ` 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` ` https://developer.android.com/reference/java/io/OutputStream#write(int)(int b) `

Writes the specified byte to this output stream.
From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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 ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

Closes this stream and releases any system resources associated with it.
From interface ` https://developer.android.com/reference/java/io/Flushable ` ` abstract void` ` https://developer.android.com/reference/java/io/Flushable#flush()() `

Flushes this stream by writing any buffered output to the underlying stream.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Public constructors

### PipedOutputStream

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

```
public PipedOutputStream ()
```

Creates a piped output stream that is not yet connected to a piped input stream. It must be connected to a piped input stream, either by the receiver or the sender, before being used.

<br />

**See also:**

- `https://developer.android.com/reference/java/io/PipedInputStream#connect(java.io.PipedOutputStream)`
- `https://developer.android.com/reference/java/io/PipedOutputStream#connect(java.io.PipedInputStream)`

### PipedOutputStream

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

```
public PipedOutputStream (PipedInputStream snk)
```

Creates a piped output stream connected to the specified piped input stream. Data bytes written to this stream will then be available as input from `snk`.

<br />

| Parameters ||
|---|---|
| `snk` | `PipedInputStream`: The piped input stream to connect to. <br /> |

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

## Public methods

### close

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

```
public void close ()
```

Closes this piped output stream and releases any system resources associated with this stream. This stream may no longer be used for writing bytes.

<br />

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

### connect

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

```
public void connect (PipedInputStream snk)
```

Connects this piped output stream to a receiver. If this object is already connected to some other piped input stream, an `IOException` is thrown.

If `snk` is an unconnected piped input stream and `src` is an unconnected piped output stream, they may be connected by either the call:
>
> ```
> src.connect(snk)
> ```
or the call:
>
> ```
> snk.connect(src)
> ```
The two calls have the same effect.

<br />

<br />

| Parameters ||
|---|---|
| `snk` | `PipedInputStream`: the piped input stream to connect to. <br /> |

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

### flush

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

```
public void flush ()
```

Flushes this output stream and forces any buffered output bytes to be written out. This will notify any readers that bytes are waiting in the pipe.

<br />

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

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

Writes `len` bytes from the specified byte array starting at offset `off` to this piped output stream. This method blocks until all the bytes are written to the output stream.

<br />

| Parameters ||
|---|---|
| `b` | `byte`: the data. <br /> |
| `off` | `int`: the start offset in the data. <br /> |
| `len` | `int`: the number of bytes to write. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the pipe is [broken](https://developer.android.com/reference/java/io/PipedOutputStream#BROKEN), `https://developer.android.com/reference/java/io/PipedOutputStream#connect(java.io.PipedInputStream)`, closed, or if an I/O error occurs. |

### write

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

```
public void write (int b)
```

Writes the specified `byte` to the piped output stream.

Implements the `write` method of `OutputStream`.

<br />

| Parameters ||
|---|---|
| `b` | `int`: the `byte` to be written. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the pipe is [broken](https://developer.android.com/reference/java/io/PipedOutputStream#BROKEN), `https://developer.android.com/reference/java/io/PipedOutputStream#connect(java.io.PipedInputStream)`, closed, or if an I/O error occurs. |