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
(§22.17) 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.
public classPipedInputStream
extends InputStream { publicPipedInputStream
(PipedOutputStream src) throws IOException; publicPipedInputStream
(); public voidconnect
(PipedOutputStream src) throws IOException; public intread
() throws IOException; public intread
(byte[] b, int off, int len) throws IOException, NullPointerException, IndexOutOfBoundsException; public voidclose
() throws IOException; }
22.5.1 public PipedInputStream(PipedOutputStream src)
throws IOException
This constructor initializes a newly created 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.
22.5.2 public PipedInputStream()
This constructor initializes a newly created PipedInputStream
so that it is not
yet connected. It must be connected to a PipedOutputStream
before being used.
22.5.3 public void connect(PipedOutputStream src)
throws IOException
The connect
method 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)
src.connect(snk)
The two calls have the same effect.
22.5.4 public int read() throws IOException
If a thread was providing data bytes to the connected piped output stream, but the
thread is no longer alive, then an IOException
is thrown.
Implements the read
method of InputStream
(§22.3.1).
22.5.5 public int read(byte[] b, int off, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException
If a thread was providing data bytes to the connected piped output stream, but the
thread is no longer alive, then an IOException
is thrown.
Overrides the read
method of InputStream
(§22.3.3).
22.5.6 public void close() throws IOException
This piped input stream is closed and may no longer be used for reading bytes.
Overrides the close
method of InputStream
(§22.3.6).