java.io.PipedInputStream
java.io.InputStream
None
None
JDK 1.0 or later
The PipedInputStream class represents half of a communication pipe; a PipedInputStream must be connected to a PipedOutputStream. When the two halves of a communication pipe are connected, data written to the PipedOutputStream can be read from the PipedInputStream. The communication pipe formed by a PipedInputStream and a PipedOutputStream should be used to communicate between threads. If both ends of a pipe are used by the same thread, the thread can hang.
public class java.io.PipedInputStream extends java.io.InputStream { // Variables protected byte[] buffer; // New in 1.1 protected int in; // New in 1.1 protected int out; // New in 1.1 protected final static int PIPE_SIZE; // New in 1.1 // Constructors public PipedInputStream(); public PipedInputStream(PipedOutputStream src); // Public Instance Methods public synchronized int available(); // New in 1.1 public void close(); public void connect(PipedOutputStream src); public synchronized int read(); public synchronized int read(byte[] b, int off, int len); // Protected Instance Methods protected synchronized void receive(int b); // New in 1.1 }
New as of JDK 1.1
The internal data buffer. The buffer receives data from the connected PipedOutputStream and supplies data for the calls to read().
New as of JDK 1.1
An index into the buffer that points to the byte after the last byte of valid data. A value of -1 indicates that the buffer is empty.
New as of JDK 1.1
An index into the buffer that points to the next byte that will be returned by read().
New as of JDK 1.1
The size of the internal data buffer. The buffer receives data from the connected PipedOutputStream and supplies data for the calls to read().
This constructor creates a PipedInputStream that is not connected to a PipedOutputStream. The created object must be connected to a PipedOutputStream before it can be used.
The PipedOutputStream to connect.
If any kind of I/O error occurs.
This constructor creates a PipedInputStream that receives data from the given PipedOutputStream.
New as of JDK 1.1
The number of bytes that can be read without blocking.
If any kind of I/O error occurs.
InputStream.available()
This method returns the number of bytes that can be read without having to wait for more data to become available. More data becomes available in the PipedInputStream when data is written to the connected PipedOutputStream.
If any kind of I/O error occurs.
InputStream.close()
This method closes the stream and releases the system resources that are associated with it.
The PipedOutputStream to connect.
If another PipedOutputStream is already connected to this PipedInputStream.
This method connects the given PipedOutputStream to this PipedInputStream object. If there is already a connected PipedOutputStream, an exception is thrown.
The next byte of data or -1 if the end of the stream is encountered.
If the pipe is broken. In other words, if this PipedInputStream is closed or if the connected PipedOutputStream is dead.
While this method is waiting for input, if the interrupted() method of the thread that invoked this method is called.
InputStream.read()
This method returns the next byte from the pipe buffer. If the buffer is empty, the method waits until data is written to the connected PipedOutputStream. The method blocks until the byte is read, the end of the stream is encountered, or an exception is thrown.
public synchronized int read(byte b[], int off, int len) throws IOException
An array of bytes to be filled.
An offset into the byte array.
The number of bytes to read.
The actual number of bytes read or -1 if the end of the stream is encountered immediately.
If the pipe is broken. In other words, if this PipedInputStream is closed or if the connected PipedOutputStream is dead.
While this method is waiting for buffer space to become available, if the interrupted() method of the thread that invoked this method is called.
InputStream.read(byte[], int, int)
This method copies bytes from the pipe buffer into the given array b, starting at index off and continuing for len bytes. If there is at least one byte in the buffer, the method returns as many bytes as are in the buffer (up to len). If the buffer is empty, the method blocks until data is written to the connected PipedOutputStream.
New as of JDK 1.1
The byte being received.
If the pipe is broken. In other words, if this PipedInputStream is closed.
This method is called by the connected PipedOutputStream object to provide the given value as a byte of input to this PipedInputStream object.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
mark(int) |
InputStream |
markSupported() |
InputStream |
notify() |
Object |
notifyAll() |
Object |
read(byte[]) |
InputStream |
reset() |
InputStream |
skip(long) |
InputStream |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
InputStream, IOException, PipedOutputStream