| |
|
| java.lang.Object java.io.InputStream java.io.PipedInputStream
PipedInputStream | public class PipedInputStream extends InputStream (Code) | | PipedInputStream is a class which receives information on a communications
pipe. When two threads want to pass data back and forth, one creates a piped
output stream and the other creates a piped input stream.
See Also: PipedOutputStream |
Field Summary | |
final protected static int | PIPE_SIZE | protected byte | buffer The circular buffer through which data is passed. | protected int | in The index in buffer where the next byte will be written. | boolean | isConnected | protected int | out The index in buffer where the next byte will be read. |
Method Summary | |
public synchronized int | available() Answers a int representing the number of bytes that are available before
this PipedInputStream will block. | public void | close() Close this PipedInputStream. | public void | connect(PipedOutputStream src) Connects this PipedInputStream to a PipedOutputStream. | synchronized void | done() | public synchronized int | read() Reads a single byte from this PipedInputStream and returns the result as
an int. | public synchronized int | read(byte[] bytes, int offset, int count) Reads at most count bytes from this PipedInputStream and
stores them in byte array buffer starting at
offset . | protected synchronized void | receive(int oneByte) Receives a byte and stores it into the PipedInputStream. |
PIPE_SIZE | final protected static int PIPE_SIZE(Code) | | The size of the default pipe in bytes
|
buffer | protected byte buffer(Code) | | The circular buffer through which data is passed.
|
in | protected int in(Code) | | The index in buffer where the next byte will be written.
|
isConnected | boolean isConnected(Code) | | Indicates if this pipe is connected
|
out | protected int out(Code) | | The index in buffer where the next byte will be read.
|
PipedInputStream | public PipedInputStream()(Code) | | Constructs a new unconnected PipedInputStream. The resulting Stream must
be connected to a PipedOutputStream before data may be read from it.
|
PipedInputStream | public PipedInputStream(PipedOutputStream out) throws IOException(Code) | | Constructs a new PipedInputStream connected to the PipedOutputStream
out . Any data written to the output stream can be read
from the this input stream.
Parameters: out - the PipedOutputStream to connect to. throws: IOException - if this or out are already connected. |
available | public synchronized int available() throws IOException(Code) | | Answers a int representing the number of bytes that are available before
this PipedInputStream will block. This method returns the number of bytes
written to the pipe but not read yet up to the size of the pipe.
int the number of bytes available before blocking. throws: IOException - If an error occurs in this stream. |
close | public void close() throws IOException(Code) | | Close this PipedInputStream. This implementation releases the buffer used
for the pipe and notifies all threads waiting to read or write.
throws: IOException - If an error occurs attempting to close this stream. |
connect | public void connect(PipedOutputStream src) throws IOException(Code) | | Connects this PipedInputStream to a PipedOutputStream. Any data written
to the OutputStream becomes readable in this InputStream.
Parameters: src - the source PipedOutputStream. throws: IOException - If either stream is already connected. |
done | synchronized void done()(Code) | | |
read | public synchronized int read() throws IOException(Code) | | Reads a single byte from this PipedInputStream and returns the result as
an int. The low-order byte is returned or -1 of the end of stream was
encountered. If there is no data in the pipe, this method blocks until
there is data available. Separate threads should be used for the reader
of the PipedInputStream and the PipedOutputStream. There may be
undesirable results if more than one Thread interacts a input or output
pipe.
int The byte read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
read | public synchronized int read(byte[] bytes, int offset, int count) throws IOException(Code) | | Reads at most count bytes from this PipedInputStream and
stores them in byte array buffer starting at
offset . Answer the number of bytes actually read or -1 if
no bytes were read and end of stream was encountered. Separate threads
should be used for the reader of the PipedInputStream and the
PipedOutputStream. There may be undesirable results if more than one
Thread interacts a input or output pipe.
Parameters: bytes - the byte array in which to store the read bytes. Parameters: offset - the offset in buffer to store the read bytes. Parameters: count - the maximum number of bytes to store in buffer . the number of bytes actually read or -1 if end of stream. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
receive | protected synchronized void receive(int oneByte) throws IOException(Code) | | Receives a byte and stores it into the PipedInputStream. This called by
PipedOutputStream.write() when writes occur. The lowest-order byte is
stored at index in in the buffer .
If the buffer is full and the thread sending #receive is interrupted, the
InterruptedIOException will be thrown.
Parameters: oneByte - the byte to store into the pipe. throws: IOException - If the stream is already closed or another IOExceptionoccurs. |
|
|
|