PipedOutputStream write Example
PipedOutputStream class write example. This example shows you how to use write method.
PipedOutputStream class write example. public void write(byte[], int ,int) throws IOException Writes len bytes from the specified byte array starting at offset off to this piped output stream. This method blocks until all the bytes are written to the output stream
Here is the code
/**
* @ # Write.java
* A class repersenting use to write method
* of PipedOutputStream class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class Write {
public static void main(String args[]) throws Exception {
PipedOutputStream poStream = new PipedOutputStream();
PipedInputStream piStream = new PipedInputStream();
// Connects piped output stream to a receiver.
poStream.connect(piStream);
//write byte array
byte b[] = {1, 2, 3, 4, 5};
poStream.write(b, 0, 5);
//Flushes output stream
poStream.flush();
System.out.println("Read from piped input stream");
while (piStream.available() != 0) {
System.out.println(piStream.read());
}
//Reads the next byte from piped input stream.
poStream.close();
piStream.close();
}
} |
Output
Read from piped input stream
1
2
3
4
5 |
|