Example usage for java.io PipedWriter PipedWriter

List of usage examples for java.io PipedWriter PipedWriter

Introduction

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

Prototype

public PipedWriter() 

Source Link

Document

Creates a piped writer that is not yet connected to a piped reader.

Usage

From source file:Main.java

public static void main(String[] args) {

    try {/*from w ww . jav  a  2 s  .c om*/
        PipedWriter writer = new PipedWriter();
        PipedReader reader = new PipedReader(writer, 100);

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

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

        // check if reader is ready to read
        System.out.println(reader.ready());

        // print the char array
        for (int i = 0; i < 2; i++) {
            System.out.println("" + (char) reader.read());
        }
        reader.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {//from  ww  w .j a v  a2 s  .com
        PipedWriter writer = new PipedWriter();
        PipedReader reader = new PipedReader(writer);

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

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

        // check if reader is ready to read
        System.out.println(reader.ready());

        // print the char array
        for (int i = 0; i < 2; i++) {
            System.out.println("" + (char) reader.read());
        }
        reader.close();
    } catch (Exception 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 {/*  w  w  w  .j  a v  a2 s.  c  o m*/
        // 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) throws IOException {
    PipedWriter pw = new PipedWriter();
    PipedReader pr = new PipedReader(pw);
    int ch;//from w ww .  j a va  2  s .  c o  m
    try {
        for (int i = 0; i < 15; i++)
            pw.write(" A" + i + '\n');
        while ((ch = pr.read()) != -1)
            System.out.print((char) ch);
    } catch (IOException e) {
    }
}

From source file:MyThread.java

public static void main(String[] args) throws Exception {
    PipedWriter pw = new PipedWriter();
    PipedReader pr = new PipedReader(pw);

    MyThread mt1 = new MyThread("src", pr, pw);
    MyThread mt2 = new MyThread("dst", pr, pw);

    mt1.start();//from  w ww . ja v  a2s . c  o m

    Thread.sleep(2000);
    mt2.start();
}

From source file:PipedCharacters.java

public static void main(String[] args) {
    try {//from   w ww  . ja  va2s.  co  m
        final PipedWriter out = new PipedWriter();

        final PipedReader in = new PipedReader(out);

        Runnable runA = new Runnable() {
            public void run() {
                writeStuff(out);
            }
        };

        Thread threadA = new Thread(runA, "threadA");
        threadA.start();

        Runnable runB = new Runnable() {
            public void run() {
                readStuff(in);
            }
        };

        Thread threadB = new Thread(runB, "threadB");
        threadB.start();
    } catch (IOException x) {
        x.printStackTrace();
    }
}

From source file:RhymingWords.java

public static Reader reverse(Reader source) throws IOException {

    BufferedReader in = new BufferedReader(source);

    PipedWriter pipeOut = new PipedWriter();
    PipedReader pipeIn = new PipedReader(pipeOut);
    PrintWriter out = new PrintWriter(pipeOut);

    new ReverseThread(out, in).start();

    return pipeIn;
}

From source file:com.github.jferard.pgloaderutils.loader.CSVCleanerFileReader.java

public CSVCleanerFileReader(CSVParser parser, CSVRecordCleaner recordCleaner) throws IOException {
    this.recordCleaner = recordCleaner;
    PipedWriter pipedWriter = new PipedWriter();
    this.modifiedStreamReader = new PipedReader(pipedWriter, BUFFER_SIZE);

    this.parser = parser;
    this.printer = new CSVPrinter(pipedWriter, CSVFormat.RFC4180);
    this.logger = Logger.getLogger("Cleaner");
}

From source file:RhymingWords.java

public static Reader sort(Reader source) throws IOException {

    BufferedReader in = new BufferedReader(source);

    PipedWriter pipeOut = new PipedWriter();
    PipedReader pipeIn = new PipedReader(pipeOut);
    PrintWriter out = new PrintWriter(pipeOut);

    new SortThread(out, in).start();

    return pipeIn;
}

From source file:com.sonicle.webtop.mail.SaxHTMLMailParser.java

public void initialize(HTMLMailData mailData, boolean justBody) throws SAXException {
    //if (writer!=null || reader!=null) throw new SAXException("SaxHTMLMailParser yet not released!");
    release();// ww  w . ja  va2  s.c o  m

    this.mailData = mailData;

    writer = new PipedWriter();
    try {
        reader = new PipedReader(writer);
    } catch (IOException exc) {
        throw new SAXException(exc);
    }
    pwriter = new PrintWriter(writer);
    breader = new BufferedReader(reader);
    this.justBody = justBody;
}