|
Chapter 11 The java.io Package |
|
PipedOutputStream
Name
PipedOutputStream
- Class Name:
-
java.io.PipedOutputStream
- Superclass:
-
java.io.OutputStream
- Immediate Subclasses:
-
None
- Interfaces Implemented:
-
None
- Availability:
-
JDK 1.0 or later
The PipedOutputStream
class represents half of a communication pipe; a PipedOutputStream
must be connected to a PipedOutputStream.
When the two halves of a communication pipe are connected, data written
to the PipedOutputStream can
be read from the PipedInputStream.
The communication pipe formed by a PipedOutputStream
and a PipedInputStream should be used to
communicate between threads. If both ends of a pipe are used by
the same thread, the thread can hang.
public class java.io.PipedOutputStream extends java.io.OutputStream {
// Constructors
public PipedOutputStream();
public PipedOutputStream(PipedInputStream snk);
// Instance Methods
public void close();
public void connect(PipedInputStream snk);
public synchronized void flush(); // New in 1.1
public void write(int b);
public void write(byte[] b, int off, int len);
}
- Description
-
This constructor creates a PipedOutputStream
that is not connected to a PipedInputStream.
The created object must be connected to a PipedInputStream
before it can be used.
- Parameters
-
- snk
-
The PipedInputStream
to connect.
- Throws
-
- IOException
-
If any kind
of I/O error occurs.
- Description
-
This constructor creates a PipedOutputStream
that sends data to the given PipedInputStream.
- Throws
-
- IOException
-
If any kind
of I/O error occurs.
- Overrides
-
OutputStream.close()
- Description
-
This method closes the stream and releases the system resources that are
associated with it.
- Parameters
-
- snk
-
The PipedInputStream
to connect.
- Throws
-
- IOException
-
If another
PipedInputStream is already
connected to this PipedOutputStream
or this PipedOutputStream is
already connected.
- Description
-
This method connects this PipedOutputStream
object to the given PipedInputStream.
If this PipedOutputStream or
snk is already connected, an
exception is thrown.
- Availability
-
New as of JDK 1.1
- Throws
-
- IOException
-
If any kind of I/O error occurs.
- InterruptedIOException
-
While this method is waiting for buffer space to become available, if
the interrupted() method of the thread that invoked
this method is called.
- Overrides
-
OutputStream.flush()
- Description
-
This method flushes the stream, which tells the connected PipedInputStream
to notify its readers to read any available data.
- Parameters
-
- b
-
The value to write.
- Throws
-
- IOException
-
If any kind of I/O error occurs.
- InterruptedIOException
-
While this method is waiting for buffer space to become available, if
the interrupted() method of the thread that invoked
this method is called.
- Overrides
-
OutputStream.write(int)
- Description
-
This method writes a byte of output. The method passes the given value
directly to the connected PipedInputStream.
- Parameters
-
- b
-
An array of bytes to write to the stream.
- off
-
An offset into the byte array.
- len
-
The number of bytes to write.
- Throws
-
- IOException
-
If any kind of I/O error occurs.
- InterruptedIOException
-
While this method is waiting for buffer space to become available, if
the interrupted() method of the thread that invoked
this method is called.
- Overrides
-
OutputStream.write(byte[], int, int)
- Description
-
This method writes len bytes
of output from the given array, starting at offset off.
The method passes the given data to the connected PipedInputStream.
IOException,
OutputStream,
PipedInputStream
|
|