Example usage for java.io PipedWriter connect

List of usage examples for java.io PipedWriter connect

Introduction

In this page you can find the example usage for java.io PipedWriter connect.

Prototype

public synchronized void connect(PipedReader snk) throws IOException 

Source Link

Document

Connects this piped writer to a receiver.

Usage

From source file:Main.java

public static void main(String[] args) {

    try {/*  w  w  w. ja va 2 s .com*/
        PipedReader reader = new PipedReader();
        PipedWriter writer = new PipedWriter(reader);

        // connect the reader and the writer
        writer.connect(reader);

        writer.write('A');
        writer.write('B');

        // print what we wrote
        for (int i = 0; i < 2; i++) {
            System.out.println((char) reader.read());
        }
        writer.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {/* www.  j  a va  2s  .c om*/
        // connect the reader and the writer
        writer.connect(reader);

        writer.write('A');
        writer.write('B');

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

    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {//from   w w w.  j  ava  2 s  . c  o m
        // connect the reader and the writer
        writer.connect(reader);

        writer.write(70);
        writer.write(71);

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

    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    char[] c = { 'h', 'e', 'l', 'l', 'o' };
    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {/*from www.  j  a v  a 2  s. c om*/
        // connect the reader and the writer
        writer.connect(reader);

        writer.write(c, 0, 3);

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

    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {//w ww  .j  av  a  2s .  c  o m
        // connect the reader and the writer
        writer.connect(reader);

        writer.write(70);
        writer.write(71);

        writer.close();

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

    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {/*www  . ja va 2  s.c o  m*/
        // connect the reader and the writer
        writer.connect(reader);

        writer.write(70);
        writer.write(71);

        // flush the writer
        writer.flush();

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

    } catch (IOException ex) {
        ex.printStackTrace();
    }

}