# PipedOutputStream

public class **PipedOutputStream** extends [OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html)  
Places information on a communications pipe. When two threads want to pass
data back and forth, one creates a piped output stream and the other one
creates a piped input stream.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html`

### Public Constructor Summary

|---|---|
|   | [PipedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#PipedOutputStream())() Constructs a new unconnected `PipedOutputStream`. |
|   | [PipedOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#PipedOutputStream(java.io.PipedInputStream))([PipedInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html) target) Constructs a new `PipedOutputStream` connected to the `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html` `target`. |

### Public Method Summary

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#close())() Closes this stream. |
| void | [connect](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#connect(java.io.PipedInputStream))([PipedInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html) stream) Connects this stream to a `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html`. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#flush())() Notifies the readers of this `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html` that bytes can be read. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#write(byte[],%20int,%20int))(byte\[\] buffer, int offset, int count) Writes `count` bytes from the byte array `buffer` starting at `offset` to this stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream.html#write(int))(int oneByte) Writes a single byte to this stream. |

### Inherited Method Summary

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

## Public Constructors

#### public
**PipedOutputStream**
()

Constructs a new unconnected `PipedOutputStream`. The resulting
stream must be connected to a `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html` before data can be
written to it.

#### public
**PipedOutputStream**
([PipedInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html) target)

Constructs a new `PipedOutputStream` connected to the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html` `target`. Any data written to this stream
can be read from the target stream.

##### Parameters

| target | the piped input stream to connect to. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if this stream or `target` are already connected. |
|---|---|

## Public Methods

#### public void
**close**
()

Closes this stream. If this stream is connected to an input stream, the
input stream is closed and the pipe is disconnected.

##### Throws

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

#### public void
**connect**
([PipedInputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html) stream)

Connects this stream to a `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html`. Any data written to
this output stream becomes readable in the input stream.

##### Parameters

| stream | the piped input stream to connect to. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if either stream is already connected. |
|---|---|

#### public void
**flush**
()

Notifies the readers of this `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html` that bytes can be
read. This method does nothing if this stream is not connected.

##### Throws

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

#### public void
**write**
(byte\[\] buffer, int offset, int count)

Writes `count` bytes from the byte array `buffer` starting at
`offset` to this stream. The written data can then be read from the
connected input stream.


Separate threads should be used to write to a `PipedOutputStream`
and to read from the connected `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html`. If the same
thread is used, a deadlock may occur.

##### Parameters

| buffer | the buffer to write. |
| offset | the index of the first byte in `buffer` to write. |
| count | the number of bytes from `buffer` to write to this stream. |
|---|---|

##### Throws

| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | if `offset < 0` or `count < 0`, or if `offset + count` is bigger than the length of `buffer`. |
| [InterruptedIOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InterruptedIOException.html) | if the pipe is full and the current thread is interrupted waiting for space to write data. This case is not currently handled correctly. |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if this stream is not connected, if the target stream is closed or if the thread reading from the target stream is no longer alive. This case is currently not handled correctly. |
|---|---|

#### public void
**write**
(int oneByte)

Writes a single byte to this stream. Only the least significant byte of
the integer `oneByte` is written. The written byte can then be read
from the connected input stream.


Separate threads should be used to write to a `PipedOutputStream`
and to read from the connected `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedInputStream.html`. If the same
thread is used, a deadlock may occur.

##### Parameters

| oneByte | the byte to write. |
|---|---|

##### Throws

| [InterruptedIOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InterruptedIOException.html) | if the pipe is full and the current thread is interrupted waiting for space to write data. This case is not currently handled correctly. |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if this stream is not connected, if the target stream is closed or if the thread reading from the target stream is no longer alive. This case is currently not handled correctly. |
|---|---|