java.lang.Object | ||
↳ | java.io.InputStream | |
↳ | java.io.PipedInputStream |
Receives information from 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.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | PIPE_SIZE | The size of the default pipe in bytes. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
buffer | The circular buffer through which data is passed. | ||||||||||
in | The index in buffer where the next byte will be written. |
||||||||||
out | The index in buffer where the next byte will be read. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new unconnected
PipedInputStream . | |||||||||||
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the number of bytes that are available before this stream will
block.
| |||||||||||
Closes this stream.
| |||||||||||
Connects this
PipedInputStream to a PipedOutputStream . | |||||||||||
Reads at most
count bytes from this stream and stores them in the
byte array bytes starting at offset . | |||||||||||
Reads a single byte from this stream and returns it as an integer in the
range from 0 to 255.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Receives a byte and stores it in this stream's
buffer . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.io.InputStream
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.io.Closeable
|
The size of the default pipe in bytes.
The circular buffer through which data is passed. Data is read from the
range [out, in)
and written to the range [in, out)
.
Data in the buffer is either sequential:
{ - - - X X X X X X X - - - - - } ^ ^ | | out in...or wrapped around the buffer's end:
{ X X X X - - - - - - - - X X X } ^ ^ | | in outWhen the buffer is empty,
in == -1
. Reading when the buffer is
empty will block until data is available. When the buffer is full,
in == out
. Writing when the buffer is full will block until free
space is available.
Constructs a new unconnected PipedInputStream
. The resulting
stream must be connected to a PipedOutputStream
before data may
be read from it.
Constructs a new PipedInputStream
connected to the
PipedOutputStream
out
. Any data written to the output
stream can be read from the this input stream.
out | the piped output stream to connect to. |
---|
IOException | if this stream or out are already connected.
|
---|
Returns the number of bytes that are available before this stream will block. This implementation returns the number of bytes written to this pipe that have not been read yet.
IOException | if an error occurs in this stream. |
---|
Closes this stream. This implementation releases the buffer used for the pipe and notifies all threads waiting to read or write.
IOException | if an error occurs while closing this stream. |
---|
Connects this PipedInputStream
to a PipedOutputStream
.
Any data written to the output stream becomes readable in this input
stream.
src | the source output stream. |
---|
IOException | if either stream is already connected. |
---|
Reads at most count
bytes from this stream and stores them in the
byte array bytes
starting at offset
. Blocks until at
least one byte has been read, the end of the stream is detected or an
exception is thrown.
Separate threads should be used to read from a PipedInputStream
and to write to the connected PipedOutputStream
. If the same
thread is used, a deadlock may occur.
bytes | the array in which to store the bytes read. |
---|---|
offset | the initial position in bytes to store the bytes
read from this stream. |
count | the maximum number of bytes to store in bytes . |
IndexOutOfBoundsException | if offset < 0 or count < 0 , or if offset + count is greater than the size of bytes . |
---|---|
InterruptedIOException | if the thread reading from this stream is interrupted. |
IOException | if this stream is closed or not connected to an output stream, or if the thread writing to the connected output stream is no longer alive. |
NullPointerException | if bytes is null .
|
Reads a single byte from this stream and returns it as an integer in the range from 0 to 255. Returns -1 if the end of this stream has been reached. If there is no data in the pipe, this method blocks until data is available, the end of the stream is detected or an exception is thrown.
Separate threads should be used to read from a PipedInputStream
and to write to the connected PipedOutputStream
. If the same
thread is used, a deadlock may occur.
IOException | if this stream is closed or not connected to an output stream, or if the thread writing to the connected output stream is no longer alive. |
---|
Receives a byte and stores it in this stream's buffer
. This
method is called by write(int)
. The least
significant byte of the integer oneByte
is stored at index
in
in the buffer
.
This method blocks as long as buffer
is full.
oneByte | the byte to store in this pipe. |
---|
InterruptedIOException | if the buffer is full and the thread that has called
this method is interrupted. |
---|---|
IOException | if this stream is closed or the thread that has last read from this stream is no longer alive. |