# PipedWriter

public class **PipedWriter** extends [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html)  
Piped character-output streams.

### Inherited Field Summary

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

|---|---|---|
| protected [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [lock](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#lock) | The object used to synchronize operations on this stream. |

### Public Constructor Summary

|---|---|
|   | [PipedWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#PipedWriter(java.io.PipedReader))([PipedReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedReader.html) snk) Creates a piped writer connected to the specified piped reader. |
|   | [PipedWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#PipedWriter())() Creates a piped writer that is not yet connected to a piped reader. |

### Public Method Summary

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#close())() Closes this piped output stream and releases any system resources associated with this stream. |
| synchronized void | [connect](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#connect(java.io.PipedReader))([PipedReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedReader.html) snk) Connects this piped writer to a receiver. |
| synchronized void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#flush())() Flushes this output stream and forces any buffered output characters to be written out. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#write(int))(int c) Writes the specified `char` to the piped output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#write(char[],%20int,%20int))(char\[\] cbuf, int off, int len) Writes `len` characters from the specified character array starting at offset `off` to this piped output stream. |

### Inherited Method Summary

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

|---|---|
| [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#append(char))(char c) Appends the specified character to this writer. |
| [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#append(java.lang.CharSequence,%20int,%20int))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq, int start, int end) Appends a subsequence of the specified character sequence to this writer. |
| [Writer](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#append(java.lang.CharSequence))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq) Appends the specified character sequence to this writer. |
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#close())() Closes the stream, flushing it first. |
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#flush())() Flushes the stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) str) Writes a string. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(int))(int c) Writes a single character. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(java.lang.String,%20int,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) str, int off, int len) Writes a portion of a string. |
| abstract void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(char[],%20int,%20int))(char\[\] cbuf, int off, int len) Writes a portion of an array of characters. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Writer.html#write(char[]))(char\[\] cbuf) Writes an array of characters. |

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.lang.Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html)

|---|---|
| abstract [Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html#append(char))(char c) Appends the specified character to this Appendable. |
| abstract [Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html#append(java.lang.CharSequence,%20int,%20int))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq, int start, int end) Appends a subsequence of the specified character sequence to this Appendable. |
| abstract [Appendable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html) | [append](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Appendable.html#append(java.lang.CharSequence))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) csq) Appends the specified character sequence to this Appendable. |

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
**PipedWriter**
([PipedReader](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedReader.html) snk)

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

##### Parameters

| snk | The piped reader to connect to. |
|---|---|

##### Throws

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

#### public
**PipedWriter**
()

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

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedReader.html#connect(java.io.PipedWriter)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#connect(java.io.PipedReader)`

## Public Methods

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

##### Throws

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

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

Connects this piped writer to a receiver. If this object
is already connected to some other piped reader, an
`IOException` is thrown.


If `snk` is an unconnected piped reader and
`src` is an unconnected piped writer, 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 />

##### Parameters

| snk | the piped reader to connect to. |
|---|---|

##### Throws

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

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

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

##### Throws

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

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

Writes the specified `char` to the piped output stream.
If a thread was reading data characters from the connected piped input
stream, but the thread is no longer alive, then an
`IOException` is thrown.


Implements the `write` method of `Writer`.

##### Parameters

| c | the `char` to be written. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if the pipe is [`broken`](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream#BROKEN), `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#connect(java.io.PipedReader)`, closed or an I/O error occurs. |
|---|---|

#### public void
**write**
(char\[\] cbuf, int off, int len)

Writes `len` characters from the specified character array
starting at offset `off` to this piped output stream.
This method blocks until all the characters are written to the output
stream.
If a thread was reading data characters from the connected piped input
stream, but the thread is no longer alive, then an
`IOException` is thrown.

##### Parameters

| cbuf | the data. |
| off | the start offset in the data. |
| len | the number of characters to write. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if the pipe is [`broken`](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedOutputStream#BROKEN), `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PipedWriter.html#connect(java.io.PipedReader)`, closed or an I/O error occurs. |
|---|---|