Skip to content

Most visited

Recently visited

navigation
Added in API level 1

PipedReader

public class PipedReader
extends Reader

java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.PipedReader


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.

See also:

Summary

Inherited fields

From class java.io.Reader

Public constructors

PipedReader()

Constructs a new unconnected PipedReader.

PipedReader(PipedWriter out)

Constructs a new PipedReader connected to the PipedWriter out.

PipedReader(int pipeSize)

Constructs a new unconnected PipedReader with the given buffer size.

PipedReader(PipedWriter out, int pipeSize)

Constructs a new PipedReader connected to the given PipedWriter, with the given buffer size.

Public methods

void close()

Closes this reader.

void connect(PipedWriter src)

Connects this PipedReader to a PipedWriter.

int read()

Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.

int read(char[] buffer, int offset, int count)

Reads up to count characters from this reader and stores them in the character array buffer starting at offset.

boolean ready()

Indicates whether this reader is ready to be read without blocking.

Inherited methods

From class java.io.Reader
From class java.lang.Object
From interface java.lang.Readable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public constructors

PipedReader

Added in API level 1
PipedReader ()

Constructs a new unconnected PipedReader. The resulting reader must be connected to a PipedWriter before data may be read from it.

PipedReader

Added in API level 1
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 PipedWriter: the PipedWriter to connect to.
Throws
IOException if out is already connected.

PipedReader

Added in API level 9
PipedReader (int pipeSize)

Constructs a new unconnected PipedReader with the given buffer size. The resulting reader must be connected to a PipedWriter before data may be read from it.

Parameters
pipeSize int: the size of the buffer in chars.
Throws
IllegalArgumentException if pipeSize is less than or equal to zero.

PipedReader

Added in API level 9
PipedReader (PipedWriter out, 
                int pipeSize)

Constructs a new PipedReader connected to the given PipedWriter, with the given buffer size. Any data written to the writer can be read from this reader.

Parameters
out PipedWriter: the PipedWriter to connect to.
pipeSize int: the size of the buffer in chars.
Throws
IOException if an I/O error occurs
IllegalArgumentException if pipeSize is less than or equal to zero.

Public methods

close

Added in API level 1
void close ()

Closes this reader. This implementation releases the buffer used for the pipe and notifies all threads waiting to read or write.

Throws
IOException if an error occurs while closing this reader.

connect

Added in API level 1
void connect (PipedWriter src)

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

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

read

Added in API level 1
int read ()

Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached. If there is no data in the pipe, this method blocks until data is available, the end of the reader is detected or an exception is thrown.

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

Returns
int the character read or -1 if the end of the reader has been reached.
Throws
IOException if this reader is closed or some other I/O error occurs.

read

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

Reads up to count characters from this reader and stores them in the character array buffer starting at offset. If there is no data in the pipe, this method blocks until at least one byte has been read, the end of the reader is detected or an exception is thrown.

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

Returns the number of characters read or -1 if the end of the reader has been reached.

Parameters
buffer char
offset int
count int
Returns
int
Throws
IndexOutOfBoundsException if offset < 0 || count < 0 || offset + count > buffer.length.
InterruptedIOException if the thread reading from this reader is interrupted.
IOException if this reader is closed or not connected to a writer, or if the thread writing to the connected writer is no longer alive.

ready

Added in API level 1
boolean ready ()

Indicates whether this reader is ready to be read without blocking. Returns true if this reader will not block when read is called, false if unknown or blocking will occur. This implementation returns true if the internal buffer contains characters that can be read.

Returns
boolean always false.
Throws
IOException if this reader is closed or not connected, or if some other I/O error occurs.

See also:

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.