java.io.PipedWriter
PipedWriter is a class which places 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 writer. |
Public Constructors
Public Methods
Methods inherited
from class
java.io.Writer
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
public
PipedWriter()
Constructs a new unconnected PipedWriter. The resulting Stream must be
connected to a PipedReader before data may be written to it.
public
PipedWriter(PipedReader dest)
Constructs a new PipedWriter connected to the PipedReader
dest
. Any data written to this Writer can be read from
the
dest
.
Parameters
dest
| the PipedReader to connect to. |
Public Methods
public
void
close()
Close this PipedWriter. Any data buffered in the corresponding
PipedReader can be read, then -1 will be returned to the reader. If this
Writer is not connected, this method does nothing.
Throws
IOException
| If an error occurs attempting to close this PipedWriter.
|
public
void
connect(PipedReader stream)
Connects this PipedWriter to a PipedReader. Any data written to this
Writer becomes readable in the Reader.
Parameters
stream
| the destination PipedReader. |
Throws
IOException
| If this Writer or the dest is already connected.
|
public
void
flush()
Notifies the readers on the PipedReader that characters can be read. This
method does nothing if this Writer is not connected.
public
void
write(char[] buffer, int offset, int count)
Writes
count
chars
from the char array
buffer
starting at offset
index
to this
PipedWriter. The written data can now be read from the destination
PipedReader. 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 input or output pipe.
Parameters
buffer
| the buffer to be written |
offset
| offset in buffer to get chars |
count
| number of chars in buffer to write |
Throws
IOException
| If the receiving thread was terminated without closing the
pipe. This case is not currently handled correctly. |
InterruptedIOException
| If the pipe is full and the current thread is interrupted
waiting for space to write data. This case is not currently
handled correctly. |
NullPointerException
| If the receiver has not been connected yet. |
IllegalArgumentException
| If any of the arguments are out of bounds.
|
public
void
write(int c)
Writes the character
c
to this PipedWriter. The written
data can now be read from the destination PipedReader. 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
input or output pipe.
Parameters
c
| the character to be written |
Throws
IOException
| If the receiving thread was terminated without closing the
pipe. This case is not currently handled correctly. |
InterruptedIOException
| If the pipe is full and the current thread is interrupted
waiting for space to write data. This case is not currently
handled correctly. |
NullPointerException
| If the receiver has not been connected yet.
|