Java PipedInputStream.available()

Syntax

PipedInputStream.available() has the following syntax.

public int available()  throws IOException

Example

In the following code shows how to use PipedInputStream.available() method.


/*w  w w  .ja va2 s. c  o m*/
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class Main {

  public static void main(String[] args) throws Exception {

    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream();

    // connect input and output
    in.connect(out);

    // write something
    out.write(70);
    out.write(71);

    // print how many bytes are available
    System.out.println(in.available());

    // read what we wrote
    for (int i = 0; i < 2; i++) {
      System.out.println("" + (char) in.read());
    }
    in.close();
  }
}

The code above generates the following result.