Java PipedOutputStream.close()

Syntax

PipedOutputStream.close() has the following syntax.

public void close()  throws IOException

Example

In the following code shows how to use PipedOutputStream.close() method.


import java.io.PipedInputStream;
import java.io.PipedOutputStream;
//from   www  .j  ava  2s . c  o m
public class Main extends PipedInputStream {

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

    // create a new Piped input and Output Stream
    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

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

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

    out.close();

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

  }
}

The code above generates the following result.