Contents | Prev | Next | Index

22.5 The Class java.io.PipedInputStream

A piped input stream should be connected to a piped output stream; the piped input stream then provides whatever data bytes are written to the piped output stream. Typically, data is read from a PipedInputStream object by one thread and data is written to the corresponding PipedOutputStream (§22.17) by some other thread. Attempting to use both objects from a single thread is not recommended, as it may deadlock the thread. The piped input stream contains a buffer, decoupling read operations from write operations, within limits.

public class PipedInputStream extends InputStream {
	public PipedInputStream(PipedOutputStream src)
		throws IOException;
	public PipedInputStream();
	public void connect(PipedOutputStream src)
		throws IOException;
	public int read() throws IOException;
	public int read(byte[] b, int off, int len) 
		throws IOException, NullPointerException,
			IndexOutOfBoundsException;
	public void close() throws IOException;
}

22.5.1 public PipedInputStream(PipedOutputStream src)
throws IOException

This constructor initializes a newly created PipedInputStream so that it is connected to the piped output stream src. Data bytes written to src will then be available as input from this stream.

22.5.2 public PipedInputStream()

This constructor initializes a newly created PipedInputStream so that it is not yet connected. It must be connected to a PipedOutputStream before being used.

22.5.3 public void connect(PipedOutputStream src)
throws IOException

The connect method causes this piped input stream to be connected to the piped output stream src. If this object is already connected to some other piped output stream, an IOException is thrown.

If src is an unconnected piped output stream and snk is an unconnected piped input stream, they may be connected by either the call:

snk.connect(src)
or the call:

src.connect(snk)
The two calls have the same effect.

22.5.4 public int read() throws IOException

If a thread was providing data bytes to the connected piped output stream, but the thread is no longer alive, then an IOException is thrown.

Implements the read method of InputStream (§22.3.1).

22.5.5 public int read(byte[] b, int off, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException

If a thread was providing data bytes to the connected piped output stream, but the thread is no longer alive, then an IOException is thrown.

Overrides the read method of InputStream (§22.3.3).

22.5.6 public void close() throws IOException

This piped input stream is closed and may no longer be used for reading bytes.

Overrides the close method of InputStream (§22.3.6).


Contents | Prev | Next | Index

Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com



Spec-Zone.ru - all specs in one place



free hit counter