public class PipedInputStream extends InputStream
Data is read and written to an internal buffer. It is highly recommended
that the PipedInputStream
and connected
PipedOutputStream
be part of different threads. If they are not, the read and write
operations could deadlock their thread.
Constructor and Description |
---|
PipedInputStream()
Creates a new
PipedInputStream that is not connected to a
PipedOutputStream . |
PipedInputStream(int pipeSize)
Creates a new
PipedInputStream of the given size that is not
connected to a PipedOutputStream . |
PipedInputStream(PipedOutputStream source)
This constructor creates a new
PipedInputStream and connects
it to the passed in PipedOutputStream . |
PipedInputStream(PipedOutputStream source,
int pipeSize)
This constructor creates a new
PipedInputStream of the given
size and connects it to the passed in PipedOutputStream . |
Modifier and Type | Method and Description |
---|---|
int |
available()
This method returns the number of bytes that can be read from this stream
before blocking could occur.
|
void |
close()
This methods closes the stream so that no more data can be read
from it.
|
void |
connect(PipedOutputStream source)
This method connects this stream to the passed in
PipedOutputStream . |
int |
read()
This method reads one byte from the stream.
|
int |
read(byte[] buf,
int offset,
int len)
This method reads bytes from the stream into a caller supplied buffer.
|
mark, markSupported, read, reset, skip
public PipedInputStream()
PipedInputStream
that is not connected to a
PipedOutputStream
. It must be connected before bytes can
be read from this stream.public PipedInputStream(int pipeSize) throws IllegalArgumentException
PipedInputStream
of the given size that is not
connected to a PipedOutputStream
.
It must be connected before bytes can be read from this stream.IllegalArgumentException
public PipedInputStream(PipedOutputStream source) throws IOException
PipedInputStream
and connects
it to the passed in PipedOutputStream
. The stream is then
ready for reading.source
- The PipedOutputStream
to connect this
stream toIOException
- If source
is already connected.public PipedInputStream(PipedOutputStream source, int pipeSize) throws IOException
PipedInputStream
of the given
size and connects it to the passed in PipedOutputStream
.
The stream is then ready for reading.source
- The PipedOutputStream
to connect this
stream toIOException
- If source
is already connected.public int available() throws IOException
available
in class InputStream
IOException
- If an error occurspublic void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
- If an error occurspublic void connect(PipedOutputStream source) throws IOException
PipedOutputStream
.
This stream is then ready for reading. If this stream is already
connected or has been previously closed, then an exception is thrownsource
- The PipedOutputStream
to connect this stream toIOException
- If this PipedInputStream or source
has been connected already.public int read() throws IOException
This method will block if no byte is available to be read.
read
in class InputStream
IOException
- if an error occuredpublic int read(byte[] buf, int offset, int len) throws IOException
offset
into the
buffer and
reads a maximum of len
bytes. Note that this method
can actually
read fewer than len
bytes. The actual number of bytes
read is
returned. A -1 is returned to indicated that no bytes can be read
because the end of the stream was reached - ie close() was called on the
connected PipedOutputStream.
This method will block if no bytes are available to be read.
read
in class InputStream
buf
- The buffer into which bytes will be storedoffset
- The index into the buffer at which to start writing.len
- The maximum number of bytes to read.IOException
- If close()
was called on this Piped
InputStream.