Java.io.PipedInputStream.read() Method
Advertisements
Description
The java.io.PipedInputStream.receive(int b) method receives a byte of data. This method will block if no input is available.
Declaration
Following is the declaration for java.io.PipedInputStream.receive() method
protected void receive(int b)
Parameters
b -- the byte being received
Return Value
This method does not return a value.
Exception
IOException -- if the pipe is broken, unconnected, closed, or if an I/O error occurs.
Example
The following example shows the usage of java.io.PipedInputStream.receive() method.
package com.tutorialspoint;
import java.io.*;
public class PipedInputStreamDemo extends PipedInputStream {
public static void main(String[] args) {
// create a new Piped input and Output Stream
PipedOutputStream out = new PipedOutputStream();
PipedInputStreamDemo in = new PipedInputStreamDemo();
try {
// connect input and output
in.connect(out);
// write something
out.write(70);
out.write(71);
// receive a byte
System.out.println("Receiving Byte...");
in.receive(71);
System.out.println("Byte Received.");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result:
Receiving Byte... Byte Received.