java.io.PipedReader
PipedReader is a class which receives information on a communications pipe.
When two threads want to pass data back and forth, one creates a piped writer
and the other creates a piped reader.
Summary
protected |
|
|
Object |
lock |
The object used to synchronize access to the reader. |
Public Constructors
Public Methods
Methods inherited
from class
java.io.Reader
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
PipedReader()
Constructs a new unconnected PipedReader. The resulting Reader must be
connected to a PipedWriter before data may be read from it.
public
PipedReader(PipedWriter out)
Constructs a new PipedReader connected to the PipedWriter
out
. Any data written to the writer can be read from the
this reader.
Parameters
out
| the PipedWriter to connect to. |
Public Methods
public
void
close()
Close this PipedReader. 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 reader.
|
public
void
connect(PipedWriter src)
Connects this PipedReader to a PipedWriter. Any data written to the
Writer becomes available in this Reader.
Parameters
src
| the source PipedWriter. |
Throws
IOException
| If either Writer or Reader is already connected.
|
public
int
read(char[] buffer, int offset, int count)
Reads at most
count
character from this PipedReader and
stores them in char array
buffer
starting at
offset
. Answer the number of characters actually read or
-1 if no characters were read and end of stream was encountered. Separate
threads should be used for the reader of the PipedReader and the
PipedWriter. There may be undesirable results if more than one Thread
interacts a reader or writer pipe.
Parameters
buffer
| the character array in which to store the read characters. |
offset
| the offset in buffer to store the read
characters. |
count
| the maximum number of characters to store in
buffer . |
Returns
- int the number of characters actually read or -1 if end of
reader.
Throws
IOException
| If the reader is already closed or another IOException
occurs.
|
public
int
read()
Reads the next character from this Reader. Answer the character actually
read or -1 if no character was read and end of reader was encountered.
Separate threads should be used for the reader of the PipedReader and the
PipedWriter. There may be undesirable results if more than one Thread
interacts a reader or writer pipe.
Returns
- int the character read -1 if end of reader.
Throws
IOException
| If the reader is already closed or another IOException
occurs.
|
public
boolean
ready()
Answer a boolean indicating whether or not this Reader is ready to be
read. Returns true if the buffer contains characters to be read.
Returns
- boolean
true
if there are characters ready,
false
otherwise.
Throws
IOException
| If the reader is already closed or another IOException
occurs.
|