Java IO: PipedOutputStream

Jakob Jenkov
Last update: 2014-11-15

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.

Jakob Jenkov

Featured Videos




















Advertisements

High-Performance
Java Persistence
Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next