Java IO: PipedOutputStream
Jakob Jenkov |
The PipedOutputStream
class makes it possible to write to a Java pipe as a stream of bytes.
Pipes are communication between threads running in the same JVM.
PipedOutputStream Example
Here is a simple PipedOutputStream
example:
OutputStream output = new PipedOutputStream(pipedInputStream); while(moreData) { int data = getMoreData(); output.write(data); } output.close();
Note: The proper exception handling has been skipped here for the sake of clarity. To learn more about correct exception handling, go to Java IO Exception Handling.
The write()
method of a PipedOutputStream
takes an int which contains the byte value of the
byte to write.
More PipedOutputStream Methods
Since PipedOutputStream
is a subclass of OutputStream
, PipedOutputStream
has
the same basic methods and use patterns as an OutputStream
. See my OutputStream
tutorial
for more information.
Java IO Pipes
The PipedOutputStream
must always be connected to a PipedInputStream
. When connected
like that, they form a Java pipe. To learn more about Java pipes, go to Java IO: Pipes.
Tweet | |
Jakob Jenkov |