Build 1.0_r1(from source)

java.io
Class PipedReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.PipedReader
All Implemented Interfaces:
Closeable, Readable

public class PipedReader
extends Reader

PipedReader is a class which 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.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
PipedReader()
          Constructs a new unconnected PipedReader.
PipedReader(PipedWriter out)
          Constructs a new PipedReader connected to the PipedWriter out.
 
Method Summary
 void close()
          Close this PipedReader.
 void connect(PipedWriter src)
          Connects this PipedReader to a PipedWriter.
(package private)  void done()
           
(package private)  void establishConnection()
          Establish the connection to the PipedWriter.
(package private)  void flush()
           
 int read()
          Reads the next character from this Reader.
 int read(char[] buffer, int offset, int count)
          Reads at most count character from this PipedReader and stores them in char array buffer starting at offset.
 boolean ready()
          Answer a boolean indicating whether or not this Reader is ready to be read.
(package private)  void receive(char oneChar)
          Receives a char and stores it into the PipedReader.
(package private)  void receive(char[] chars, int offset, int count)
          Receives a char array and stores it into the PipedReader.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PipedReader

public PipedReader()
Constructs a new unconnected PipedReader. The resulting Reader must be connected to a PipedWriter before data may be read from it.


PipedReader

public PipedReader(PipedWriter out)
            throws IOException
Constructs a new PipedReader connected to the PipedWriter out. Any data written to the writer can be read from the this reader.

Parameters:
out - the PipedWriter to connect to.
Throws:
IOException - if this or out are already connected.
Method Detail

close

public void close()
           throws IOException
Close this PipedReader. This implementation releases the buffer used for the pipe and notifies all threads waiting to read or write.

Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException - If an error occurs attempting to close this reader.

connect

public void connect(PipedWriter src)
             throws IOException
Connects this PipedReader to a PipedWriter. Any data written to the Writer becomes available in this Reader.

Parameters:
src - the source PipedWriter.
Throws:
IOException - If either Writer or Reader is already connected.

establishConnection

void establishConnection()
                   throws IOException
Establish the connection to the PipedWriter.

Throws:
IOException - If this Reader is already connected.

read

public int read()
         throws IOException
Reads the next character from this Reader. Answer the character actually read or -1 if no character was read and end of reader was encountered. 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 reader or writer pipe.

Overrides:
read in class Reader
Returns:
int the character read -1 if end of reader.
Throws:
IOException - If the reader is already closed or another IOException occurs.

read

public int read(char[] buffer,
                int offset,
                int count)
         throws IOException
Reads at most count character from this PipedReader and stores them in char array buffer starting at offset. Answer the number of characters actually read or -1 if no characters were read and end of stream was encountered. 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 reader or writer pipe.

Specified by:
read in class Reader
Parameters:
buffer - the character array in which to store the read characters.
offset - the offset in buffer to store the read characters.
count - the maximum number of characters to store in buffer.
Returns:
int the number of characters actually read or -1 if end of reader.
Throws:
IOException - If the reader is already closed or another IOException occurs.

ready

public boolean ready()
              throws IOException
Answer a boolean indicating whether or not this Reader is ready to be read. Returns true if the buffer contains characters to be read.

Overrides:
ready in class Reader
Returns:
boolean true if there are characters ready, false otherwise.
Throws:
IOException - If the reader is already closed or another IOException occurs.

receive

void receive(char oneChar)
       throws IOException
Receives a char and stores it into the PipedReader. This called by PipedWriter.write() when writes occur.

If the buffer is full and the thread sending #receive is interrupted, the InterruptedIOException will be thrown.

Parameters:
oneChar - the char to store into the pipe.
Throws:
IOException - If the stream is already closed or another IOException occurs.

receive

void receive(char[] chars,
             int offset,
             int count)
       throws IOException
Receives a char array and stores it into the PipedReader. This called by PipedWriter.write() when writes occur.

If the buffer is full and the thread sending #receive is interrupted, the InterruptedIOException will be thrown.

Parameters:
chars - the char array to store into the pipe.
offset - offset to start reading from
count - total characters to read
Throws:
IOException - If the stream is already closed or another IOException occurs.

done

void done()

flush

void flush()

Build 1.0_r1(from source)

Please submit a feedback, bug or feature