PipedInputStream

public class PipedInputStream extends InputStream

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.

Constant Summary

int PIPE_SIZE The size of the default pipe in bytes.

Field Summary

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.
protected int out The index in buffer where the next byte will be read.

Public Constructor Summary

PipedInputStream()
Constructs a new unconnected PipedInputStream.
PipedInputStream(PipedOutputStream out)
Constructs a new PipedInputStream connected to the PipedOutputStream out.
PipedInputStream(int pipeSize)
Constructs a new unconnected PipedInputStream with the given buffer size.
PipedInputStream(PipedOutputStream out, int pipeSize)
Constructs a new PipedInputStream connected to the given PipedOutputStream, with the given buffer size.

Public Method Summary

synchronized int
available()
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.

Unlike most streams, PipedInputStream returns 0 rather than throwing IOException if the stream has been closed.

synchronized void
close()
Closes this stream.
void
connect(PipedOutputStream src)
Connects this PipedInputStream to a PipedOutputStream.
synchronized int
read()
Reads a single byte from this stream and returns it as an integer in the range from 0 to 255.
synchronized int
read(byte[] bytes, int offset, int byteCount)
Reads at most byteCount bytes from this stream and stores them in the byte array bytes starting at offset.

Protected Method Summary

synchronized void
receive(int oneByte)
Receives a byte and stores it in this stream's buffer.

Inherited Method Summary

Constants

protected static final int PIPE_SIZE

The size of the default pipe in bytes.

Constant Value: 1024

Fields

protected byte[] buffer

The circular buffer through which data is pas