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 = {12345};
        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, 05);

        //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();
    }
}

Output
No. of byte Available 5

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US