Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class Main extends PipedInputStream {

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

        byte[] b = { 'h', 'e', 'l', 'l', 'o' };

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

        out.connect(in);

        // write something
        out.write(b, 0, 3);

        // flush the stream
        out.flush();

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