Build 1.0_r1(from source)

java.io
Class PipedWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PipedWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class PipedWriter
extends Writer

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:
PipedReader

Field Summary
 
Fields inherited from class java.io.Writer
lock, TOKEN_NULL
 
Constructor Summary
PipedWriter()
          Constructs a new unconnected PipedWriter.
PipedWriter(PipedReader dest)
          Constructs a new PipedWriter connected to the PipedReader dest.
 
Method Summary
 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.
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PipedWriter

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


PipedWriter

public PipedWriter(PipedReader dest)
            throws IOException
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.
Method Detail

close

public void close()
           throws IOException
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.

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

connect

public void connect(PipedReader stream)
             throws IOException
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.

flush

public void flush()
           throws IOException
Notifies the readers on the PipedReader that characters can be read. This method does nothing if this Writer is not connected.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException - If an IO error occurs during the flush.

write

public void write(char[] buffer,
                  int offset,
                  int count)
           throws IOException
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.

Specified by:
write in class Writer
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.

write

public void write(int c)
           throws IOException
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.

Overrides:
write in class Writer
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.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature