// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class Pip2 {
    private static final int N = 10000000;
    public static void main(String[] args) throws Exception {
        final PipedOutputStream pos = new PipedOutputStream();
        final PipedInputStream pis = new PipedInputStream(pos);
        Thread t = new Thread() {
            public void run() {
                try {
                    for(int i = 0; i < N; i++) {
                        pos.write(i % 256);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        long t1 = System.currentTimeMillis();
        t.start();
        for(int i = 0; i < N; i++) {
            int c = pis.read();
            if(c != i % 256) {
                throw new Exception("Ooops");
            }
        }
        long t2 = System.currentTimeMillis();
        System.out.println((1000 * N) / (t2 - t1));
    }
}
