# PipedReader

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

# PipedReader

`
public


class
PipedReader
`  
`


``

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


``


`

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

<br />

*** ** * ** ***

Piped character-input streams.

## Summary

|                                                                                                                                                                                                                                                    ### Inherited fields                                                                                                                                                                                                                                                    |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From class[java.io.Reader](https://developer.android.com/reference/java/io/Reader) |---------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------| | ` protected `[Object](https://developer.android.com/reference/java/lang/Object) | [lock](https://developer.android.com/reference/java/io/Reader#lock) The object used to synchronize operations on this stream. | |

|                                                                                                                                                                  ### Public constructors                                                                                                                                                                  ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[PipedReader](https://developer.android.com/reference/java/io/PipedReader#PipedReader())`() ` Creates a`PipedReader`so that it is not yet[connected](https://developer.android.com/reference/java/io/PipedReader#connect(java.io.PipedWriter)).                                                                                                     |
| ` `[PipedReader](https://developer.android.com/reference/java/io/PipedReader#PipedReader(int))`(int pipeSize) ` Creates a`PipedReader`so that it is not yet[connected](https://developer.android.com/reference/java/io/PipedReader#connect(java.io.PipedWriter))and uses the specified pipe size for the pipe's buffer.                                |
| ` `[PipedReader](https://developer.android.com/reference/java/io/PipedReader#PipedReader(java.io.PipedWriter))`(`[PipedWriter](https://developer.android.com/reference/java/io/PipedWriter)` src) ` Creates a`PipedReader`so that it is connected to the piped writer`src`.                                                                            |
| ` `[PipedReader](https://developer.android.com/reference/java/io/PipedReader#PipedReader(java.io.PipedWriter,%20int))`(`[PipedWriter](https://developer.android.com/reference/java/io/PipedWriter)` src, int pipeSize) ` Creates a`PipedReader`so that it is connected to the piped writer`src`and uses the specified pipe size for the pipe's buffer. |

|                                                                                                                             ### Public methods                                                                                                                             ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`    | ` `[close](https://developer.android.com/reference/java/io/PipedReader#close())`() ` Closes this piped stream and releases any system resources associated with the stream.                                                                                    |
| ` void`    | ` `[connect](https://developer.android.com/reference/java/io/PipedReader#connect(java.io.PipedWriter))`(`[PipedWriter](https://developer.android.com/reference/java/io/PipedWriter)` src) ` Causes this piped reader to be connected to the piped writer`src`. |
| ` int`     | ` `[read](https://developer.android.com/reference/java/io/PipedReader#read())`() ` Reads the next character of data from this piped stream.                                                                                                                    |
| ` int`     | ` `[read](https://developer.android.com/reference/java/io/PipedReader#read(char[],%20int,%20int))`(char[] cbuf, int off, int len) ` Reads up to`len`characters of data from this piped stream into an array of characters.                                     |
| ` boolean` | ` `[ready](https://developer.android.com/reference/java/io/PipedReader#ready())`() ` Tell whether this stream is ready to be read.                                                                                                                             |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.io.Reader](https://developer.android.com/reference/java/io/Reader)` ` |----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void`                                                           | ` `[close](https://developer.android.com/reference/java/io/Reader#close())`() ` Closes the stream and releases any system resources associated with it.                                                                                                                                            | | ` void`                                                                    | ` `[mark](https://developer.android.com/reference/java/io/Reader#mark(int))`(int readAheadLimit) ` Marks the present position in the stream.                                                                                                                                                       | | ` boolean`                                                                 | ` `[markSupported](https://developer.android.com/reference/java/io/Reader#markSupported())`() ` Tells whether this stream supports the mark() operation.                                                                                                                                           | | ` static `[Reader](https://developer.android.com/reference/java/io/Reader) | ` `[nullReader](https://developer.android.com/reference/java/io/Reader#nullReader())`() ` Returns a new`Reader`that reads no characters.                                                                                                                                                           | | ` int`                                                                     | ` `[read](https://developer.android.com/reference/java/io/Reader#read())`() ` Reads a single character.                                                                                                                                                                                            | | ` abstract int`                                                            | ` `[read](https://developer.android.com/reference/java/io/Reader#read(char[],%20int,%20int))`(char[] cbuf, int off, int len) ` Reads characters into a portion of an array.                                                                                                                        | | ` int`                                                                     | ` `[read](https://developer.android.com/reference/java/io/Reader#read(char[]))`(char[] cbuf) ` Reads characters into an array.                                                                                                                                                                     | | ` int`                                                                     | ` `[read](https://developer.android.com/reference/java/io/Reader#read(java.nio.CharBuffer))`(`[CharBuffer](https://developer.android.com/reference/java/nio/CharBuffer)` target) ` Attempts to read characters into the specified character buffer.                                                | | ` boolean`                                                                 | ` `[ready](https://developer.android.com/reference/java/io/Reader#ready())`() ` Tells whether this stream is ready to be read.                                                                                                                                                                     | | ` void`                                                                    | ` `[reset](https://developer.android.com/reference/java/io/Reader#reset())`() ` Resets the stream.                                                                                                                                                                                                 | | ` long`                                                                    | ` `[skip](https://developer.android.com/reference/java/io/Reader#skip(long))`(long n) ` Skips characters.                                                                                                                                                                                          | | ` long`                                                                    | ` `[transferTo](https://developer.android.com/reference/java/io/Reader#transferTo(java.io.Writer))`(`[Writer](https://developer.android.com/reference/java/io/Writer)` out) ` Reads all characters from this reader and writes the characters to the given writer in the order that they are read. | ||
| 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.lang.Readable](https://developer.android.com/reference/java/lang/Readable)` ` |-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract int` | ` `[read](https://developer.android.com/reference/java/lang/Readable#read(java.nio.CharBuffer))`(`[CharBuffer](https://developer.android.com/reference/java/nio/CharBuffer)` cb) ` Attempts to read characters into the specified character buffer. | ||
| 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. | ||

## Public constructors

### PipedReader

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

```
public PipedReader ()
```

Creates a`PipedReader`so that it is not yet[connected](https://developer.android.com/reference/java/io/PipedReader#connect(java.io.PipedWriter)). It must be[connected](https://developer.android.com/reference/java/io/PipedWriter#connect(java.io.PipedReader))to a`PipedWriter`before being used.

<br />

### PipedReader

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

```
public PipedReader (int pipeSize)
```

Creates a`PipedReader`so that it is not yet[connected](https://developer.android.com/reference/java/io/PipedReader#connect(java.io.PipedWriter))and uses the specified pipe size for the pipe's buffer. It must be[connected](https://developer.android.com/reference/java/io/PipedWriter#connect(java.io.PipedReader))to a`PipedWriter`before being used.

<br />

|                        Parameters                        ||
|------------|----------------------------------------------|
| `pipeSize` | `int`: the size of the pipe's buffer. <br /> |

|                                                           Throws                                                           ||
|--------------------------------------------------------------------------------------------------------|--------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if`pipeSize <= 0`. |

### PipedReader

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

```
public PipedReader (PipedWriter src)
```

Creates a`PipedReader`so that it is connected to the piped writer`src`. Data written to`src`will then be available as input from this stream.

<br />

|                       Parameters                       ||
|-------|-------------------------------------------------|
| `src` | `PipedWriter`: the stream to connect to. <br /> |

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

### PipedReader

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

```
public PipedReader (PipedWriter src, 
                int pipeSize)
```

Creates a`PipedReader`so that it is connected to the piped writer`src`and uses the specified pipe size for the pipe's buffer. Data written to`src`will then be available as input from this stream.

<br />

|                         Parameters                          ||
|------------|-------------------------------------------------|
| `src`      | `PipedWriter`: the stream to connect to. <br /> |
| `pipeSize` | `int`: the size of the pipe's buffer. <br />    |

|                                                             Throws                                                              ||
|--------------------------------------------------------------------------------------------------------|-------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException)                             | if an I/O error occurs. |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if`pipeSize <= 0`.      |

## 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 stream and releases any system resources associated with the stream.

<br />

|                                               Throws                                                ||
|----------------------------------------------------------------------------|-------------------------|
| [IOException](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 (PipedWriter src)
```

Causes this piped reader to be connected to the piped writer`src`. If this object is already connected to some other piped writer, an`IOException`is thrown.

If`src`is an unconnected piped writer and`snk`is an unconnected piped reader, they may be connected by either the call:  

    snk.connect(src) 

or the call:  

    src.connect(snk) 

The two calls have the same effect.

<br />

|                          Parameters                          ||
|-------|-------------------------------------------------------|
| `src` | `PipedWriter`: The piped writer to connect to. <br /> |

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

### read

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

```
public int read ()
```

Reads the next character of data from this piped stream. If no character is available because the end of the stream has been reached, the value`-1`is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

<br />

|                                       Returns                                        ||
|-------|-------------------------------------------------------------------------------|
| `int` | the next character of data, or`-1`if the end of the stream is reached. <br /> |

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

### read

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

```
public int read (char[] cbuf, 
                int off, 
                int len)
```

Reads up to`len`characters of data from this piped stream into an array of characters. Less than`len`characters will be read if the end of the data stream is reached or if`len`exceeds the pipe's buffer size. This method blocks until at least one character of input is available.

<br />

|                           Parameters                           ||
|--------|--------------------------------------------------------|
| `cbuf` | `char`: the buffer into which the data is read. <br /> |
| `off`  | `int`: the start offset of the data. <br />            |
| `len`  | `int`: the maximum number of characters read. <br />   |

|                                                                      Returns                                                                      ||
|-------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | the total number of characters read into the buffer, or`-1`if there is no more data because the end of the stream has been reached. <br /> |

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

### ready

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

```
public boolean ready ()
```

Tell whether this stream is ready to be read. A piped character stream is ready if the circular buffer is not empty.

<br />

|                                                                                   Returns                                                                                    ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `boolean` | True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block. <br /> |

|                                                                                                                                              Throws                                                                                                                                               ||
|----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if the pipe is[`broken`](https://developer.android.com/reference/java/io/PipedInputStream#BROKEN),[unconnected](https://developer.android.com/reference/java/io/PipedReader#connect(java.io.PipedWriter)), or closed. |