Class java.io.PipedInputStream
java.lang.Object
|
+----java.io.InputStream
|
+----java.io.PipedInputStream
- public class PipedInputStream
- extends InputStream
A piped input stream can be connected to a piped output stream
to create a communications pipe. The piped input stream is the
receiving end of the pipe. Two threads can communicate by having
one thread send data to a piped output stream and having the other
thread read the data from the connected piped input stream.
- Since:
- JDK1.0
- See Also:
- PipedOutputStream
Field Summary
|
byte[]
|
buffer
The circular buffer into which incoming data is placed.
|
int
|
in
The index of the position in the circular buffer at which the
next byte of data will be stored when received from the connected
piped output stream.
|
int
|
out
The index of the position in the circular buffer at which the next
byte of data will be read by this piped input stream.
|
static int
|
PIPE_SIZE
The size of the pipe's circular input buffer.
|
Method Summary
|
int
|
available()
Returns the number of bytes that can be read from this input
stream without blocking.
|
void
|
close()
Closes this piped input stream and releases any system resources
associated with the stream.
|
void
|
connect(PipedOutputStream src)
Connects this piped input stream to a sender.
|
int
|
read()
Reads the next byte of data from this piped input stream.
|
int
|
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this piped input
stream into an array of bytes.
|
void
|
receive(int b)
Receives a byte of data.
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PIPE_SIZE
protected static final int PIPE_SIZE
- The size of the pipe's circular input buffer.
buffer
protected byte[] buffer
- The circular buffer into which incoming data is placed.
in
protected int in
- The index of the position in the circular buffer at which the
next byte of data will be stored when received from the connected
piped output stream.
in<0
implies the buffer is empty,
in==out
implies the buffer is full
out
protected int out
- The index of the position in the circular buffer at which the next
byte of data will be read by this piped input stream.
PipedInputStream
public PipedInputStream(PipedOutputStream src) throws IOException
- Creates a piped input stream connected to the specified piped
output stream.
- Parameters:
src
- the stream to connect to.
- Throws:
- IOException - if an I/O error occurs.
PipedInputStream
public PipedInputStream()
- Creates a piped input stream that is not yet connected to a piped
output stream. It must be connected to a piped output stream,
either by the receiver or the sender, before being used.
- See Also:
- connect(java.io.PipedOutputStream), connect(java.io.PipedInputStream)
connect
public void connect(PipedOutputStream src) throws IOException
- Connects this piped input stream to a sender.
- Parameters:
src
- The piped output stream to connect to.
- Throws:
- IOException - if an I/O error occurs.
receive
protected void receive(int b) throws IOException
- Receives a byte of data. This method will block if no input is
available.
- Parameters:
b
- the byte being received
- Throws:
- IOException - If the pipe is broken.
read
public int read() throws IOException
- Reads the next byte of data from this piped input stream. The
value byte is returned as an
int
in the range
0
to 255
. If no byte is available
because the end of the stream has been reached, the value
-1
is returned. This method blocks until input data
is available, the end of the stream is detected, or an exception
is thrown.
- Returns:
- the next byte of data, or
-1
if the end of the
stream is reached. - Throws:
- IOException - if the pipe is broken.
- Overrides:
- read in class InputStream
read
public int read(byte[] b,
int off,
int len) throws IOException
- Reads up to
len
bytes of data from this piped input
stream into an array of bytes. Less than len
bytes
will be read if the end of the data stream is reached. This method
blocks until at least one byte of input is available.
- Parameters:
b
- the buffer into which the data is read.
off
- the start offset of the data.
len
- the maximum number of bytes read.
- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of
the stream has been reached. - Throws:
- IOException - if an I/O error occurs.
- Overrides:
- read in class InputStream
available
public int available() throws IOException
- Returns the number of bytes that can be read from this input
stream without blocking.
- Returns:
- the number of bytes that can be read from this input stream
without blocking.
- Throws:
- IOException - if an I/O error occurs.
- Overrides:
- available in class InputStream
close
public void close() throws IOException
- Closes this piped input stream and releases any system resources
associated with the stream.
- Throws:
- IOException - if an I/O error occurs.
- Overrides:
- close in class InputStream
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.