Methods Summary |
---|
public void | close()Closes this writer. If a {@link PipedReader} is connected to this writer,
it is closed as well and the pipe is disconnected. Any data buffered in
the reader can still be read.
synchronized (lock) {
/* Is the pipe connected? */
if (dest != null) {
dest.done();
dest = null;
}
closed = true;
}
|
public void | connect(java.io.PipedReader stream)Connects this {@code PipedWriter} to a {@link PipedReader}. Any data
written to this writer becomes readable in the reader.
synchronized (lock) {
if (this.dest != null) {
throw new IOException(Msg.getString("K0079")); //$NON-NLS-1$
}
if (closed) {
throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
}
stream.establishConnection();
this.dest = stream;
}
|
public void | flush()Notifies the readers of this {@code PipedReader} that characters can be read. This
method does nothing if this Writer is not connected.
if (dest != null) {
dest.flush();
}
|
public void | write(char[] buffer, int offset, int count)Writes {@code count} characters from the character array {@code buffer}
starting at offset {@code index} to this writer. The written data can
then be read from the connected {@link PipedReader} instance.
Separate threads should be used to write to a {@code PipedWriter} and to
read from the connected {@code PipedReader}. If the same thread is used,
a deadlock may occur.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
synchronized (lock) {
if (closed) {
throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
}
if (dest == null) {
throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
}
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
// BEGIN android-changed
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, used (offset | count) < 0
// instead of (offset < 0) || (count < 0) to safe one operation
if ((offset | count) < 0 || count > buffer.length - offset) {
throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
dest.receive(buffer, offset, count);
}
|
public void | write(int c)Writes a single character {@code c} to this writer. This character can
then be read from the connected {@link PipedReader} instance.
Separate threads should be used to write to a {@code PipedWriter} and to
read from the connected {@code PipedReader}. If the same thread is used,
a deadlock may occur.
synchronized (lock) {
if (closed) {
throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
}
if (dest == null) {
throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
}
dest.receive((char) c);
}
|