Skip to content

Most visited

Recently visited

navigation
Added in API level 1

PipedOutputStream

public class PipedOutputStream
extends OutputStream

java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.PipedOutputStream


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:

Summary

Public constructors

PipedOutputStream()

Constructs a new unconnected PipedOutputStream.

PipedOutputStream(PipedInputStream target)

Constructs a new PipedOutputStream connected to the PipedInputStream target.

Public methods

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 methods

From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public constructors

PipedOutputStream

Added in API level 1
PipedOutputStream ()

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

PipedOutputStream

Added in API level 1
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 PipedInputStream: the piped input stream to connect to.
Throws
IOException if this stream or target are already connected.

Public methods

close

Added in API level 1
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.

connect

Added in API level 1
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 PipedInputStream: the piped input stream to connect to.
Throws
IOException if either stream is already connected.

flush

Added in API level 1
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.

write

Added in API level 1
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. If the same thread is used, a deadlock may occur.

Parameters
buffer byte: the buffer to write.
offset int: the index of the first byte in buffer to write.
count int: the number of bytes from buffer to write to this stream.
Throws
IndexOutOfBoundsException if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.
InterruptedIOException if the pipe is full and the current thread is interrupted waiting for space to write data. This case is not currently handled correctly.
IOException if this stream is not connected, if the target stream is closed or if the thread reading from the target stream is no longer alive.

write

Added in API level 1
void write (int oneByte)

Writes a single byte to this stream. Only the least significant byte of the integer oneByte is written. The written byte 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. If the same thread is used, a deadlock may occur.

Parameters
oneByte int: the byte to write.
Throws
InterruptedIOException if the pipe is full and the current thread is interrupted waiting for space to write data. This case is not currently handled correctly.
IOException if this stream is not connected, if the target stream is closed or if the thread reading from the target stream is no longer alive. This case is currently not handled correctly.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.