PipedWriter
Stay organized with collections
Save and categorize content based on your preferences.
Piped character-output streams.
Public Constructor Summary
|
|
|
PipedWriter()
Creates a piped writer that is not yet connected to a
piped reader.
|
Public Method Summary
void
|
close()
Closes this piped output stream and releases any system resources
associated with this stream.
|
synchronized
void
|
|
synchronized
void
|
flush()
Flushes this output stream and forces any buffered output characters
to be written out.
|
void
|
write(int c)
Writes the specified char to the piped output stream.
|
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.
|
Inherited Method Summary
From class
java.io.Writer
Writer
|
append(char c)
Appends the specified character to this writer.
|
Writer
|
append( CharSequence csq, int start, int end)
Appends a subsequence of the specified character sequence to this writer.
|
Writer
|
|
abstract
void
|
close()
Closes the stream, flushing it first.
|
abstract
void
|
flush()
Flushes the stream.
|
void
|
|
void
|
write(int c)
Writes a single character.
|
void
|
write( String str, int off, int len)
Writes a portion of a string.
|
abstract
void
|
write(char[] cbuf, int off, int len)
Writes a portion of an array of characters.
|
void
|
write(char[] cbuf)
Writes an array of characters.
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
From interface
java.io.Closeable
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
From interface
java.io.Flushable
abstract
void
|
flush()
Flushes this stream by writing any buffered output to the underlying
stream.
|
Public Constructors
public
PipedWriter
(PipedReader snk)
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 |
The piped reader to connect to. |
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.
Public Methods
public
void
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.
public
synchronized
void
connect
(PipedReader snk)
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)
or the call:
snk.connect(src)
The two calls have the same effect.
Parameters
snk |
the piped reader to connect to. |
public
synchronized
void
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.
Throws
IOException |
if the pipe is closed, or an I/O error occurs.
|
public
void
write
(int c)
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 |
the char to be written. |
public
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.
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 |
the data. |
off |
the start offset in the data. |
len |
the number of characters to write. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003ePipedWriter\u003c/code\u003e is a character-output stream used for communication between threads, connecting to a \u003ccode\u003ePipedReader\u003c/code\u003e to facilitate data transfer.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003ewrite\u003c/code\u003e, \u003ccode\u003eflush\u003c/code\u003e, \u003ccode\u003eclose\u003c/code\u003e, and \u003ccode\u003econnect\u003c/code\u003e to write data, clear buffers, release resources, and establish connections, respectively.\u003c/p\u003e\n"],["\u003cp\u003eConstructors enable creation of a \u003ccode\u003ePipedWriter\u003c/code\u003e instance, either already linked to a \u003ccode\u003ePipedReader\u003c/code\u003e or to be connected later.\u003c/p\u003e\n"],["\u003cp\u003eSeveral methods are inherited from superclasses such as \u003ccode\u003eWriter\u003c/code\u003e, \u003ccode\u003eObject\u003c/code\u003e, \u003ccode\u003eAppendable\u003c/code\u003e, \u003ccode\u003eCloseable\u003c/code\u003e, \u003ccode\u003eFlushable\u003c/code\u003e, and \u003ccode\u003eAutoCloseable\u003c/code\u003e, offering additional functionality.\u003c/p\u003e\n"],["\u003cp\u003eIf the connected \u003ccode\u003ePipedReader\u003c/code\u003e's reading thread terminates, using \u003ccode\u003ePipedWriter\u003c/code\u003e methods like \u003ccode\u003ewrite\u003c/code\u003e may result in an \u003ccode\u003eIOException\u003c/code\u003e.\u003c/p\u003e\n"]]],["`PipedWriter` is for character-output streams, offering methods to manage data flow. Key actions include creating a `PipedWriter`, optionally connecting it to a `PipedReader` upon creation or later using `connect()`. Data is written via `write()`, either a single character or a character array. `flush()` ensures data is sent, notifying readers. `close()` releases resources and ends the stream. Operations can throw `IOException` if the pipe is broken, unconnected, or closed.\n"],null,[]]