PipedOutputStream

public class PipedOutputStream extends OutputStream

Places information on a communications pipe. When two threads want to pass data back and forth, one creates a piped output stream and the other one creates a piped input stream.

See Also

Public Constructor Summary

PipedOutputStream()
Constructs a new unconnected PipedOutputStream.
PipedOutputStream(PipedInputStream target)
Constructs a new PipedOutputStream connected to the PipedInputStream target.

Public Method Summary

void
close()
Closes this stream.
void
connect(PipedInputStream stream)
Connects this stream to a PipedInputStream.
void
flush()
Notifies the readers of this PipedInputStream that bytes can be read.
void
write(byte[] buffer, int offset, int count)
Writes count bytes from the byte array buffer starting at offset to this stream.
void
write(int oneByte)
Writes a single byte to this stream.

Inherited Method Summary

Public Constructors

public PipedOutputStream ()

Constructs a new unconnected PipedOutputStream. The resulting stream must be connected to a PipedInputStream before data can be written to it.

public PipedOutputStream (PipedInputStream target)

Constructs a new PipedOutputStream connected to the PipedInputStream target. Any data written to this stream can be read from the target stream.

Parameters
target the piped input stream to connect to.
Throws
IOException if this stream or target are already connected.

Public Methods

public void close ()

Closes this stream. If this stream is connected to an input stream, the input stream is closed and the pipe is disconnected.

Throws
IOException if an error occurs while closing this stream.

public void connect (PipedInputStream stream)

Connects this stream to a PipedInputStream. Any data written to this output stream becomes readable in the input stream.

Parameters
stream the piped input stream to connect to.
Throws
IOException if either stream is already connected.

public void flush ()

Notifies the readers of this PipedInputStream that bytes can be read. This method does nothing if this stream is not connected.

Throws
IOException if an I/O error occurs while flushing this stream.

public void write (byte[] buffer, int offset, int count)

Writes count bytes from the byte array buffer starting at offset to this stream. The written data can then be read from the connected input stream.

Separate threads should be used to write to a PipedOutputStream and to read from the connected PipedInputStream