PipedInputStream available Example
PipedInputStream class available example. This example shows you how to use available method.
PipedInputStream class available example. public int available() throws IOException Returns the number of bytes that can be read from this input stream without blocking.
Here is the code
/**
* @ # Available.java
* A class repersenting use to Available method
* of PipedInputStream class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class Available {
public static void main(String args[]) throws Exception {
byte[] b = {1, 2, 3, 4, 5};
PipedOutputStream poStream = new PipedOutputStream();
PipedInputStream piStream = new PipedInputStream();
//piped input stream connect to the piped output stream
piStream.connect(poStream);
//Writes specified byte array.
poStream.write(b, 0, 5);
//number of bytes that can be read from this input stream.
System.out.println("No. of byte Available " + piStream.available());
// Closes piped input stream
poStream.close();
// Closes piped output stream
piStream.close();
}
} |
|