import java.io.IOException;

public class PipeScannerTest {
    public static void main(String[] args) throws InterruptedException {
        Pipe pipe = new Pipe();
        final PipeTestScanner scanner = new PipeTestScanner(pipe);
        Thread scannerThread = new Thread(new Runnable() {
            public void run() {
                try {
                    scanner.next();
                } catch(IOException e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }}, "ScannerThread");
        scannerThread.start();
        
        System.out.println("Writing 'z'");
        pipe.write('z');
        System.out.println("Value = " + scanner.getMessage());
        
        System.out.println("Writing 'a'");
        pipe.write('a');
        System.out.println("Value = " + scanner.getMessage());
        
        System.out.println("Writing 'b'");
        pipe.write('b');
        System.out.println("Value = " + scanner.getMessage());
        
        System.out.println("Writing 'c'");
        pipe.write('c');
        System.out.println("Value = " + scanner.getMessage());
        
        System.out.println("Writing '\\n' (final)");
        pipe.writeFinal('\n');
        System.out.println("Value = " + scanner.getMessage());
        
        System.out.println("Before join");
        long start = System.currentTimeMillis();
        scannerThread.join();
        long end = System.currentTimeMillis();
        System.out.println("After join (" + (end - start) + "ms)");
    }
}
