加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090319163711/http://developer.android.com:80/reference/java/io/PipedWriter.html
public class

PipedWriter

extends Writer
java.lang.Object
   ↳ java.io.Writer
     ↳ java.io.PipedWriter

Class Overview

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.

See Also

Summary

[Expand]
Inherited Fields
From class java.io.Writer
Public Constructors
PipedWriter()
Constructs a new unconnected PipedWriter.
PipedWriter(PipedReader dest)
Constructs a new PipedWriter connected to the PipedReader dest.
Public Methods
void close()
Close this PipedWriter.
void connect(PipedReader stream)
Connects this PipedWriter to a PipedReader.
void flush()
Notifies the readers on the PipedReader that characters can be read.
void write(char[] buffer, int offset, int count)
Writes count chars from the char array buffer starting at offset index to this PipedWriter.
void write(int c)
Writes the character c to this PipedWriter.
[Expand]
Inherited Methods
From class java.io.Writer
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.Appendable

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.
Throws
IOException if dest is already connected.

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.

Throws
IOException If an IO error occurs during the flush.

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.