Skip to content

Most visited

Recently visited

navigation
Added in API level 1

PipedWriter

public class PipedWriter
extends Writer

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


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

Inherited fields

From class java.io.Writer

Public constructors

PipedWriter()

Constructs a new unconnected PipedWriter.

PipedWriter(PipedReader destination)

Constructs a new PipedWriter connected to destination.

Public methods

void close()

Closes this writer.

void connect(PipedReader reader)

Connects this PipedWriter to a PipedReader.

void flush()

Notifies the readers of this PipedReader that characters can be read.

void write(char[] buffer, int offset, int count)

Writes count characters from the character array buffer starting at offset index to this writer.

void write(int c)

Writes a single character c to this writer.

Inherited methods

From class java.io.Writer
From class java.lang.Object
From interface java.lang.Appendable
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public constructors

PipedWriter

Added in API level 1
PipedWriter ()

Constructs a new unconnected PipedWriter. The resulting writer must be connected to a PipedReader before data may be written to it.

See also:

PipedWriter

Added in API level 1
PipedWriter (PipedReader destination)

Constructs a new PipedWriter connected to destination. Any data written to this writer can be read from destination.

Parameters
destination PipedReader: the PipedReader to connect to.
Throws
IOException if destination is already connected.

Public methods

close

Added in API level 1
void close ()

Closes this writer. If a 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.

Throws
IOException if an error occurs while closing this writer.

connect

Added in API level 1
void connect (PipedReader reader)

Connects this PipedWriter to a PipedReader. Any data written to this writer becomes readable in the reader.

Parameters
reader PipedReader: the reader to connect to.
Throws
IOException if this writer is closed or already connected, or if reader is already connected.

flush

Added in API level 1
void flush ()

Notifies the readers of this PipedReader that characters can be read. This method does nothing if this Writer is not connected.

Throws
IOException if an I/O error occurs while flushing this writer.

write

Added in API level 1
void write (char[] buffer, 
                int offset, 
                int count)

Writes count characters from the character array buffer starting at offset index to this writer. The written data can then be read from the connected PipedReader instance.

Separate threads should be used to write to a PipedWriter and to read from the connected PipedReader. If the same thread is used, a deadlock may occur.

Parameters
buffer char: the buffer to write.
offset int: the index of the first character in buffer to write.
count int: the number of characters from buffer to write to this writer.
Throws
IndexOutOfBoundsException if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.
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.
IOException if this writer is closed or not connected, if the target reader is closed or if the thread reading from the target reader is no longer alive. This case is currently not handled correctly.
NullPointerException if buffer is null.

write

Added in API level 1
void write (int c)

Writes a single character c to this writer. This character can then be read from the connected PipedReader instance.

Separate threads should be used to write to a PipedWriter and to read from the connected PipedReader. If the same thread is used, a deadlock may occur.

Parameters
c int: the character to write.
Throws
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.
IOException if this writer is closed or not connected, if the target reader is closed or if the thread reading from the target reader is no longer alive. This case is currently not handled correctly.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.