Packages  This Package  Prev  Next  Index  

§2.16 Class PipedInputStream

public  class  java.io.PipedInputStream
    extends  java.io.InputStream  (I-§2.13)
{
        // Constructors
    public PipedInputStream();	§2.16.1
    public PipedInputStream(PipedOutputStream  src);	§2.16.2

        // Methods
    public void close();	§2.16.3
    public void connect(PipedOutputStream  src);	§2.16.4
    public int read();	§2.16.5
    public int read(byte  b[], int  off, int  len);	§2.16.6
}
A piped input stream is the receiving end a communications pipe. Two threads can communicate by having one thread send data through a piped output stream (I-§2.17) and having the other thread read the data through a piped input stream.


Constructors

PipedInputStream

public PipedInputStream()
Creates a piped input stream that is not yet connected to a piped output stream. It must be connected to a piped output stream, either by the receiver (I-§2.16.4) or the sender (I-§2.17.4), before being used.

PipedInputStream

public PipedInputStream(PipedOutputStream src) throws IOException
Creates a piped input stream connected to the specified piped output stream.
Parameters:
src - the stream to connect to.
Throws
IOException (I-§2.29)
If an I/O error occurs.

Methods

close

public void close() throws IOException
Closes this piped input stream and releases any system resources associated with the stream.
Throws
IOException (I-§2.29)
If an I/O error occurs.
Overrides:
close in class InputStream (I-§2.13.3).

connect

public void connect(PipedOutputStream src) throws IOException
Connects this piped input stream to a sender.
Parameters:
src - The piped output stream to connect to.
Throws
IOException (I-§2.29)
If an I/O error occurs.

read

public int read() throws IOException
Reads the next byte of data from this piped input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because this end of the stream has been reached, the value -1 is returned. This method blocks until either input data is available, the end of the stream is detected, or an exception is thrown.
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws
IOException (I-§2.29)
If the pipe is broken.
Overrides:
read in class InputStream (I-§2.13.6).

read

public int read(byte b[], int off, int len) throws IOException
Reads up to len bytes of data from this piped input stream into an array of bytes. This method blocks until at least one byte of input is available.
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws
IOException (I-§2.29)
If an I/O error occurs.
Overrides:
read in class InputStream (I-§2.13.8).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com