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.
java.io.PipedOutputStream
Modifier and Type | Field and Description |
---|---|
protected byte[] | buffer
The circular buffer into which incoming data is placed. |
pack-priv volatile boolean | |
pack-priv boolean | |
pack-priv boolean | |
private static final int | |
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. |
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. |
protected static final int | PIPE_SIZE
The default size of the pipe's circular input buffer. |
pack-priv Thread | |
pack-priv Thread |
Access | Constructor and Description |
---|---|
public | PipedInputStream(PipedOutputStream
the stream to connect to. src)Creates a |
public | PipedInputStream(PipedOutputStream
the stream to connect to. src, int the size of the pipe's buffer. pipeSize)Creates a |
public | |
public | PipedInputStream(int
the size of the pipe's buffer. pipeSize)Creates a |
Modifier and Type | Method and Description |
---|---|
public synchronized int | Returns: the number of bytes that can be read from this input stream without blocking, or0 if this input stream has been
closed by invoking its close() method, or if the pipe
is unconnected , or
broken .Overrides java. Returns the number of bytes that can be read from this input stream without blocking. |
private void | |
private void | |
public void | close()
Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream. |
public void | connect(PipedOutputStream
The piped output stream to connect to. src)Causes this piped input stream to be connected
to the piped output stream |
private void | |
public synchronized int | Returns: the next byte of data, or-1 if the end of the
stream is reached.Implements abstract java. Reads the next byte of data from this piped input stream. |
public synchronized int | Returns: 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.the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. Reads up to |
protected synchronized void | |
pack-priv synchronized void | receive(byte[]
the buffer into which the data is received b, int the start offset of the data off, int the maximum number of bytes received len)Receives data into an array of bytes. |
pack-priv synchronized void |
buffer | back to summary |
---|---|
protected byte[] buffer The circular buffer into which incoming data is placed.
|
closedByReader | back to summary |
---|---|
pack-priv volatile boolean closedByReader |
closedByWriter | back to summary |
---|---|
pack-priv boolean closedByWriter |
connected | back to summary |
---|---|
pack-priv boolean connected |
DEFAULT_PIPE_SIZE | back to summary |
---|---|
private static final int DEFAULT_PIPE_SIZE |
in | back to summary |
---|---|
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.
|
out | back to summary |
---|---|
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.
|
PIPE_SIZE | back to summary |
---|---|
protected static final int PIPE_SIZE The default size of the pipe's circular input buffer.
|
readSide | back to summary |
---|---|
pack-priv Thread readSide |
writeSide | back to summary |
---|---|
pack-priv Thread writeSide |
PipedInputStream | back to summary |
---|---|
public PipedInputStream(PipedOutputStream src) throws IOException Creates a
|
PipedInputStream | back to summary |
---|---|
public PipedInputStream(PipedOutputStream src, int pipeSize) throws IOException Creates a
|
PipedInputStream | back to summary |
---|---|
public PipedInputStream() Creates a |
PipedInputStream | back to summary |
---|---|
public PipedInputStream(int pipeSize) Creates a
|
available | back to summary |
---|---|
public synchronized int available() throws IOException Overrides java. Returns the number of bytes that can be read from this input stream without blocking.
|
awaitSpace | back to summary |
---|---|
private void awaitSpace() throws IOException |
checkStateForReceive | back to summary |
---|---|
private void checkStateForReceive() throws IOException |
close | back to summary |
---|---|
public void close() throws IOException Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
|
connect | back to summary |
---|---|
public void connect(PipedOutputStream src) throws IOException Causes this piped input stream to be connected
to the piped output stream
If snk.connect(src) or the call: src.connect(snk) The two calls have the same effect.
|
initPipe | back to summary |
---|---|
private void initPipe(int pipeSize) |
read | back to summary |
---|---|
public synchronized int read() throws IOException Implements abstract java. Reads the next byte of data from this piped input stream. The
value byte is returned as an
|
read | back to summary |
---|---|
public synchronized int read(byte[] b, int off, int len) throws IOException Overrides java. Reads up to
|
receive | back to summary |
---|---|
protected synchronized void receive(int b) throws IOException Receives a byte of data. This method will block if no input is available.
|
receive | back to summary |
---|---|
pack-priv synchronized void receive(byte[] b, int off, int len) throws IOException Receives data into an array of bytes. This method will block until some input is available.
|
receivedLast | back to summary |
---|---|
pack-priv synchronized void receivedLast() Notifies all waiting threads that the last byte of data has been received. |