加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090321133112/http://developer.android.com:80/reference/java/io/PipedOutputStream.html
public class

PipedOutputStream

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

Class Overview

PipedOutputStream is a class which 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 creates a piped input stream.

See Also

Summary

Public Constructors
PipedOutputStream()
Constructs a new unconnected PipedOutputStream.
PipedOutputStream(PipedInputStream dest)
Constructs a new PipedOutputStream connected to the PipedInputStream dest.
Public Methods
void close()
Close this PipedOutputStream.
void connect(PipedInputStream stream)
Connects this PipedOutputStream to a PipedInputStream.
void flush()
Notifies the readers on the PipedInputStream that bytes can be read.
void write(int oneByte)
Writes the specified byte oneByte to this PipedOutputStream.
void write(byte[] buffer, int offset, int count)
Writes count bytes from this byte array buffer starting at offset index to this PipedOutputStream.
[Expand]
Inherited Methods
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable

Public Constructors

public PipedOutputStream ()

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

public PipedOutputStream (PipedInputStream dest)

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

Parameters
dest the PipedInputStream to connect to.
Throws
IOException if dest is already connected.

Public Methods

public void close ()

Close this PipedOutputStream. Any data buffered in the corresponding PipedInputStream can be read, then -1 will be returned to the reader. If this OutputStream is not connected, this method does nothing.

Throws
IOException If an error occurs attempting to close this PipedOutputStream.

public void connect (PipedInputStream stream)

Connects this PipedOutputStream to a PipedInputStream. Any data written to this OutputStream becomes readable in the InputStream.

Parameters
stream the destination PipedInputStream.
Throws
IOException If this Stream or the dest is already connected.

public void flush ()

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

Throws
IOException If an IO error occurs during the flush.

public void write (int oneByte)

Writes the specified byte oneByte to this PipedOutputStream. Only the low order byte of oneByte is written. The data can now be read from the destination PipedInputStream. Separate threads should be used for the reader of the PipedInputStream and the PipedOutputStream. There may be undesirable results if more than one Thread interacts a input or output pipe.

Parameters
oneByte the byte to be written
Throws
IOException If the receiving thread was terminated without closing the pipe. This case is not currently handled correctly.
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.
NullPointerException If the receiver has not been connected yet.

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

Writes count bytes from this byte array buffer starting at offset index to this PipedOutputStream. The written data can now be read from the destination PipedInputStream. Separate threads should be used for the reader of the PipedInputStream and the PipedOutputStream. There may be undesirable results if more than one Thread interacts a input or output pipe.

Parameters
buffer the buffer to be written
offset offset in buffer to get bytes
count number of bytes in buffer to write
Throws
IOException If the receiving thread was terminated without closing the pipe. This case is not currently handled correctly.
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.
NullPointerException If the receiver has not been connected yet.
IllegalArgumentException If any of the arguments are out of bounds.