APIdia Launch Partner
Top Description Fields Constructors Methods
java.io

public Class PipedWriter

extends Writer
Class Inheritance
Imports
java.util.Objects

Piped character-output streams.
Author
Mark Reinhold
Since
1.1

Field Summary

Modifier and TypeField and Description
private boolean
private PipedReader
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
PipedWriter(PipedReader
The piped reader to connect to.
snk
)

Creates a piped writer connected to the specified piped reader.

public
PipedWriter()

Creates a piped writer that is not yet connected to a piped reader.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes this piped output stream and releases any system resources associated with this stream.

public synchronized void
connect(PipedReader
the piped reader to connect to.
snk
)

Connects this piped writer to a receiver.

public synchronized void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output characters to be written out.

public void
write(int
the char to be written.
c
)

Overrides java.io.Writer.write.

Writes the specified char to the piped output stream.

public void
write(char[]
the data.
cbuf
,
int
the start offset in the data.
off
,
int
the number of characters to write.
len
)

Implements abstract java.io.Writer.write.

Writes len characters from the specified character array starting at offset off to this piped output stream.

Inherited from java.io.Writer:
appendappendappendnullWriterwritewritewrite

Field Detail

closedback to summary
private boolean closed
sinkback to summary
private PipedReader sink

Constructor Detail

PipedWriterback to summary
public PipedWriter(PipedReader snk) throws IOException

Creates a piped writer connected to the specified piped reader. Data characters written to this stream will then be available as input from snk.

Parameters
snk:PipedReader

The piped reader to connect to.

Annotations
@SuppressWarnings:this-escape
Exceptions
IOException:
if an I/O error occurs.
PipedWriterback to summary
public PipedWriter()

Creates a piped writer that is not yet connected to a piped reader. It must be connected to a piped reader, either by the receiver or the sender, before being used.

See Also
java.io.PipedReader#connect(java.io.PipedWriter), java.io.PipedWriter#connect(java.io.PipedReader)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes this piped output stream and releases any system resources associated with this stream. This stream may no longer be used for writing characters.

Exceptions
IOException:
if an I/O error occurs.
connectback to summary
public synchronized void connect(PipedReader snk) throws IOException

Connects this piped writer to a receiver. If this object is already connected to some other piped reader, an IOException is thrown.

If snk is an unconnected piped reader and src is an unconnected piped writer, they may be connected by either the call:

src.connect(snk)
src.connect(snk)
or the call:
snk.connect(src)
snk.connect(src)
The two calls have the same effect.
Parameters
snk:PipedReader

the piped reader to connect to.

Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public synchronized void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output characters to be written out. This will notify any readers that characters are waiting in the pipe.

Exceptions
IOException:
if the pipe is closed, or an I/O error occurs.
writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Writes the specified char to the piped output stream. If a thread was reading data characters from the connected piped input stream, but the thread is no longer alive, then an IOException is thrown.

Implements the write method of Writer.

Parameters
c:int

the char to be written.

Exceptions
IOException:
if the pipe is broken, unconnected, closed or an I/O error occurs.
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Writes len characters from the specified character array starting at offset off to this piped output stream. This method blocks until all the characters are written to the output stream. If a thread was reading data characters from the connected piped input stream, but the thread is no longer alive, then an IOException is thrown.

Parameters
cbuf:char[]

the data.

off:int

the start offset in the data.

len:int

the number of characters to write.

Exceptions
IOException:
if the pipe is broken, unconnected, closed or an I/O error occurs.
IndexOutOfBoundsException:
If off is negative, or len is negative, or off + len is negative or greater than the length of the given array