Java PipedInputStream(int pipeSize) Constructor

Syntax

PipedInputStream(int pipeSize) constructor from PipedInputStream has the following syntax.

public PipedInputStream(int pipeSize)

Example

In the following code shows how to use PipedInputStream.PipedInputStream(int pipeSize) constructor.


import java.io.PipedInputStream;
import java.io.PipedOutputStream;
/*  w  w w .  j  ava2  s . c om*/
public class Main {

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

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

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

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

    // 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.