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

# PipedInputStream

` public class PipedInputStream `   
` ` ` extends https://developer.android.com/reference/java/io/InputStream ` ` `

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

<br />

*** ** * ** ***

A piped input stream should be connected to a piped output stream; the piped input stream then provides whatever data bytes are written to the piped output stream. Typically, data is read from a `PipedInputStream` object by one thread and data is written to the corresponding `PipedOutputStream` by some other thread. Attempting to use both objects from a single thread is not recommended, as it may deadlock the thread. The piped input stream contains a buffer, decoupling read operations from write operations, within limits. A pipe is said to be *broken* if a thread that was providing data bytes to the connected piped output stream is no longer alive.
**See also:**

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

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/java/io/PipedInputStream#PIPE_SIZE` The default size of the pipe's circular input buffer. |

| ### Fields ||
|---|---|
| ` protected byte[]` | `https://developer.android.com/reference/java/io/PipedInputStream#buffer` The circular buffer into which incoming data is placed. |
| ` protected int` | `https://developer.android.com/reference/java/io/PipedInputStream#in` The index of the position in the circular buffer at which the next byte of data will be stored when received from the connected piped output stream. |
| ` protected int` | `https://developer.android.com/reference/java/io/PipedInputStream#out` The index of the position in the circular buffer at which the next byte of data will be read by this piped input stream. |

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

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/java/io/PipedInputStream#available()() ` Returns the number of bytes that can be read from this input stream without blocking. |
| ` void` | ` https://developer.android.com/reference/java/io/PipedInputStream#close()() ` Closes this piped input stream and releases any system resources associated with the stream. |
| ` void` | ` https://developer.android.com/reference/java/io/PipedInputStream#connect(java.io.PipedOutputStream)(https://developer.android.com/reference/java/io/PipedOutputStream src) ` Causes this piped input stream to be connected to the piped output stream `src`. |
| ` int` | ` https://developer.android.com/reference/java/io/PipedInputStream#read()() ` Reads the next byte of data from this piped input stream. |
| ` int` | ` https://developer.android.com/reference/java/io/PipedInputStream#read(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads up to `len` bytes of data from this piped input stream into an array of bytes. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/io/PipedInputStream#receive(int)(int b) ` Receives a byte of data. |

### Inherited methods

From class ` https://developer.android.com/reference/java/io/InputStream ` ` int` ` https://developer.android.com/reference/java/io/InputStream#available()() `

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.
` void` ` https://developer.android.com/reference/java/io/InputStream#close()() `

Closes this input stream and releases any system resources associated with the stream.
` void` ` https://developer.android.com/reference/java/io/InputStream#mark(int)(int readlimit) `

Marks the current position in this input stream.
` boolean` ` https://developer.android.com/reference/java/io/InputStream#markSupported()() `

Tests if this input stream supports the `mark` and `reset` methods.
` static https://developer.android.com/reference/java/io/InputStream` ` https://developer.android.com/reference/java/io/InputStream#nullInputStream()() `

Returns a new `InputStream` that reads no bytes.
` int` ` https://developer.android.com/reference/java/io/InputStream#read(byte[])(byte[] b) `

Reads some number of bytes from the input stream and stores them into the buffer array `b`.
` abstract int` ` https://developer.android.com/reference/java/io/InputStream#read()() `

Reads the next byte of data from the input stream.
` int` ` https://developer.android.com/reference/java/io/InputStream#read(byte[],%20int,%20int)(byte[] b, int off, int len) `

Reads up to `len` bytes of data from the input stream into an array of bytes.
` byte[]` ` https://developer.android.com/reference/java/io/InputStream#readAllBytes()() `

Reads all remaining bytes from the input stream.
` int` ` https://developer.android.com/reference/java/io/InputStream#readNBytes(byte[],%20int,%20int)(byte[] b, int off, int len) `

Reads the requested number of bytes from the input stream into the given byte array.
` byte[]` ` https://developer.android.com/reference/java/io/InputStream#readNBytes(int)(int len) `

Reads up to a specified number of bytes from the input stream.
` void` ` https://developer.android.com/reference/java/io/InputStream#reset()() `

Repositions this stream to the position at the time the `mark` method was last called on this input stream.
` long` ` https://developer.android.com/reference/java/io/InputStream#skip(long)(long n) `

Skips over and discards `n` bytes of data from this input stream.
` void` ` https://developer.android.com/reference/java/io/InputStream#skipNBytes(long)(long n) `

Skips over and discards exactly `n` bytes of data from this input stream.
` long` ` https://developer.android.com/reference/java/io/InputStream#transferTo(java.io.OutputStream)(https://developer.android.com/reference/java/io/OutputStream out) `

Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read.
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/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Constants

### PIPE_SIZE

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

```
protected static final int PIPE_SIZE
```

The default size of the pipe's circular input buffer.

<br />

Constant Value: 1024 (0x00000400)

## Fields

### buffer

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

```
protected byte[] buffer
```

The circular buffer into which incoming data is placed.

<br />

### in

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

```
protected int in
```

The index of the position in the circular buffer at which the next byte of data will be stored when received from the connected piped output stream. `in<0` implies the buffer is empty, `in==out` implies the buffer is full

<br />

### out

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

```
protected int out
```

The index of the position in the circular buffer at which the next byte of data will be read by this piped input stream.

<br />

## Public constructors

### PipedInputStream

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

```
public PipedInputStream ()
```

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

<br />

### PipedInputStream

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

```
public PipedInputStream (int pipeSize)
```

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

<br />

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

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

### PipedInputStream

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

```
public PipedInputStream (PipedOutputStream src)
```

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

<br />

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

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

### PipedInputStream

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

```
public PipedInputStream (PipedOutputStream src, 
                int pipeSize)
```

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

<br />

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

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

## Public methods

### available

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

```
public int available ()
```

Returns the number of bytes that can be read from this input stream without blocking.

<br />

| Returns ||
|---|---|
| `int` | the number of bytes that can be read from this input stream without blocking, or `0` if this input stream has been closed by invoking its `https://developer.android.com/reference/java/io/PipedInputStream#close()` method, or if the pipe is `https://developer.android.com/reference/java/io/PipedInputStream#connect(java.io.PipedOutputStream)`, or [`broken`](https://developer.android.com/reference/java/io/PipedInputStream#BROKEN). <br /> |

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

### close

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

```
public void close ()
```

Closes this piped input stream and releases any system resources associated with the stream.

<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 (PipedOutputStream src)
```

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

If `src` is an unconnected piped output stream and `snk` is an unconnected piped input stream, 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` | `PipedOutputStream`: The piped output stream to connect to. <br /> |

| Throws ||
|---|---|
| `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 byte of data from this piped input stream. The value byte is returned as an `int` in the range `0` to `255`. 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 byte of data, or `-1` if the end of the stream is reached. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the pipe is `https://developer.android.com/reference/java/io/PipedInputStream#connect(java.io.PipedOutputStream)`, [`broken`](https://developer.android.com/reference/java/io/PipedInputStream#BROKEN), closed, or 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 (byte[] b, 
                int off, 
                int len)
```

Reads up to `len` bytes of data from this piped input stream into an array of bytes. Less than `len` bytes will be read if the end of the data stream is reached or if `len` exceeds the pipe's buffer size. If `len ` is zero, then no bytes are read and 0 is returned; otherwise, the method blocks until at least 1 byte of input is available, end of the stream has been detected, or an exception is thrown.

<br />

| Parameters ||
|---|---|
| `b` | `byte`: the buffer into which the data is read. <br /> |
| `off` | `int`: the start offset in the destination array `b` <br /> |
| `len` | `int`: the maximum number of bytes read. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the pipe is [`broken`](https://developer.android.com/reference/java/io/PipedInputStream#BROKEN), `https://developer.android.com/reference/java/io/PipedInputStream#connect(java.io.PipedOutputStream)`, closed, or if an I/O error occurs. |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | If `off` is negative, `len` is negative, or `len` is greater than `b.length - off` |
| `https://developer.android.com/reference/java/lang/NullPointerException` | If `b` is `null`. |

## Protected methods

### receive

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

```
protected void receive (int b)
```

Receives a byte of data. This method will block if no input is available.

<br />

| Parameters ||
|---|---|
| `b` | `int`: the byte being received <br /> |

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