public class PipedWriter
extends java.io.Writer
java.io.PipedWriter
class.Constructor and Description |
---|
PipedWriter()
Creates a piped writer that is not yet connected to a
piped reader.
|
PipedWriter(PipedReader snk)
Creates a piped writer connected to the specified piped
reader.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this piped output stream and releases any system resources
associated with this stream.
|
void |
connect(PipedReader snk)
Connects this piped writer to a receiver.
|
void |
flush()
Flushes this output stream and forces any buffered output characters
to be written out.
|
void |
setWriterThread()
Mark the thread that is writing to the pipe.
|
void |
write(char[] cbuf,
int off,
int len)
Writes
len characters from the specified character array
starting at offset off to this piped output stream. |
void |
write(int c)
Writes the specified
char to the piped output stream. |
public PipedWriter(PipedReader snk) throws java.io.IOException
snk
.snk
- The piped reader to connect to.java.io.IOException
- if an I/O error occurs.public PipedWriter()
PipedReader.connect(java.io.PipedWriter)
,
PipedWriter.connect(java.io.PipedReader)
public void connect(PipedReader snk) throws java.io.IOException
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:
or the call:src.connect(snk)
The two calls have the same effect.snk.connect(src)
snk
- the piped reader to connect to.java.io.IOException
- if an I/O error occurs.public void setWriterThread()
public void write(int c) throws java.io.IOException
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
.
write
in class java.io.Writer
c
- the char
to be written.java.io.IOException
- if the pipe is broken,
unconnected
, closed
or an I/O error occurs.public void write(char[] cbuf, int off, int len) throws java.io.IOException
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. This method requires that the single
writer thread register itself with setWriterThread()
prior to first calling this method.write
in class java.io.Writer
cbuf
- the data.off
- the start offset in the data.len
- the number of characters to write.java.io.IOException
- if the pipe is
broken
,
unconnected
, closed
or an I/O error occurs.public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.Writer
java.io.IOException
- if the pipe is closed, or an I/O error occurs.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer
java.io.IOException
- if an I/O error occurs.