Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.io

Class PipedReader

java.lang.Object
|
+--java.io.Reader
   |
   +--java.io.PipedReader


public class PipedReader

extends Reader

An input stream that reads characters from a piped writer to which it is connected.

Data is read and written to an internal buffer. It is highly recommended that the PipedReader and connected PipedWriter be part of different threads. If they are not, there is a possibility that the read and write operations could deadlock their thread.

Author:

Constructor Summary

PipedReader()

Creates a new PipedReader that is not connected to a PipedWriter.
PipedReader(java.io.PipedWriter source)

This constructor creates a new PipedReader and connects it to the passed in PipedWriter.

Method Summary

voidclose()

This methods closes the stream so that no more data can be read from it.
voidconnect(java.io.PipedWriter source)

This method connects this stream to the passed in PipedWriter.
intread()

This method reads chars from the stream into a caller supplied buffer.
intread(char[] buf, int offset, int len)

This method reads characters from the stream into a caller supplied buffer.
booleanready()

Constructor Details

PipedReader

public PipedReader()

Creates a new PipedReader that is not connected to a PipedWriter. It must be connected before chars can be read from this stream.


PipedReader

public PipedReader(java.io.PipedWriter source)

This constructor creates a new PipedReader and connects it to the passed in PipedWriter. The stream is then ready for reading.

Parameters:

Throws:


Method Details

close

public void close()

This methods closes the stream so that no more data can be read from it.

Throws:


connect

public void connect(java.io.PipedWriter source)

This method connects this stream to the passed in PipedWriter. This stream is then ready for reading. If this stream is already connected or has been previously closed, then an exception is thrown

Parameters:

Throws:


read

public int read()

This method reads chars from the stream into a caller supplied buffer. It starts storing chars at position offset into the buffer and reads a maximum of len chars. Note that this method can actually read fewer than len chars. The actual number of chars read is returned. A -1 is returned to indicated that no chars can be read because the end of the stream was reached. If the stream is already closed, a -1 will again be returned to indicate the end of the stream.

This method will block if no chars are available to be read.


read

public int read(char[] buf, int offset, int len)

This method reads characters from the stream into a caller supplied buffer. It starts storing chars at position offset into the buffer and reads a maximum of len chars. Note that this method can actually read fewer than len chars. The actual number of chars read is returned. A -1 is returned to indicated that no chars can be read because the end of the stream was reached - ie close() was called on the connected PipedWriter.

This method will block if no chars are available to be read.

Parameters:

Throws:


ready

public boolean ready()