Top Description Fields Constructors Methods
java.io

public Class PipedOutputStream

extends OutputStream
Class Inheritance
Imports
java.util.Objects

A piped output stream can be connected to a piped input stream to create a communications pipe. The piped output stream is the sending end of the pipe. Typically, data is written to a PipedOutputStream object by one thread and data is read from the connected PipedInputStream by some other thread. Attempting to use both objects from a single thread is not recommended as it may deadlock the thread. The pipe is said to be broken if a thread that was reading data bytes from the connected piped input stream is no longer alive.
Author
James Gosling
Since
1.0
See Also
java.io.PipedInputStream

Field Summary

Modifier and TypeField and Description
private volatile PipedInputStream

Constructor Summary

AccessConstructor and Description
public
PipedOutputStream(PipedInputStream
The piped input stream to connect to.
snk
)

Creates a piped output stream connected to the specified piped input stream.

public
PipedOutputStream()

Creates a piped output stream that is not yet connected to a piped input stream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

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

public synchronized void
connect(PipedInputStream
the piped input stream to connect to.
snk
)

Connects this piped output stream to a receiver.

public synchronized void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

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

public void
write(int
the byte to be written.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to the piped output stream.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

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

Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

sinkback to summary
private volatile PipedInputStream sink

Constructor Detail

PipedOutputStreamback to summary
public PipedOutputStream(PipedInputStream snk) throws IOException

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

Parameters
snk:PipedInputStream

The piped input stream to connect to.

Exceptions
IOException:
if an I/O error occurs.
PipedOutputStreamback to summary
public PipedOutputStream()

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

See Also
java.io.PipedInputStream#connect(java.io.PipedOutputStream), java.io.PipedOutputStream#connect(java.io.PipedInputStream)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.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 bytes.

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

Connects this piped output stream to a receiver. If this object is already connected to some other piped input stream, an IOException is thrown.

If snk is an unconnected piped input stream and src is an unconnected piped output stream, 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:PipedInputStream

the piped input stream to connect to.

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

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Writes the specified byte to the piped output stream.

Implements the write method of OutputStream.

Parameters
b:int

the byte to be written.

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

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this piped output stream. This method blocks until all the bytes are written to the output stream.

Parameters
b:byte[]

Doc from java.io.OutputStream.write.

the data.

off:int

Doc from java.io.OutputStream.write.

the start offset in the data.

len:int

Doc from java.io.OutputStream.write.

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if the pipe is broken, unconnected, closed, or if an I/O error occurs.
IndexOutOfBoundsException:
If off is negative, len is negative, or len is greater than b.length - off