Package java.io
Class PipedInputStream
int read()
Overrides:
Throws:
int read(byte[] buf, int offset, int len)
Overrides:
Throws:
_INSERT_METHOD_SIGNATURE_HERE_
Description:
read() method:
This method 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. -1 is returned, if no byte is available because the end of the stream has been reached. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. 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.
read(byte[] buf, int offset, int len) method:
This method reads up to len bytes of data from this piped input stream into an array of bytes. Less then len bytes will be read if the end of the data stream is reached. This method blocks until at least one byte of input is available. 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.
Example
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
byte[] b = {10,20};
pos.write(b, 0, 2);
if (pis.available() > 0)
Console.println("data: " + pis.read());
else
Console.println("no data");
The piped input read method reads the data from the piped output stream and prints it to the console.