Example usage for java.io PipedWriter close

List of usage examples for java.io PipedWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this piped output stream and releases any system resources associated with this stream.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    try {/*  w w w .  ja v a 2 s . c om*/
        // 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) {

    try {/*  w w  w  .j  a v  a  2s .  c om*/
        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:org.apache.rat.Report.java

/**
 * //from   www .ja  va  2 s .  c o m
 * Output a report that is styled using a defined stylesheet.
 * 
 * @param out the writer to write the report to
 * @param base the files or directories to report on
 * @param style an input stream representing the stylesheet to use for styling the report
 * @param pConfiguration current report configuration.
 * 
 * @throws FileNotFoundException in case of I/O errors.
 * @throws IOException in case of I/O errors.
 * @throws TransformerConfigurationException in case of XML errors.
 * @throws InterruptedException in case of threading errors.
 * @throws RatException in case of internal errors.
 * 
 * @return the currently collected numerical statistics.
 */
public static ClaimStatistic report(Writer out, IReportable base, final InputStream style,
        ReportConfiguration pConfiguration) throws IOException, TransformerConfigurationException,
        FileNotFoundException, InterruptedException, RatException {
    PipedReader reader = new PipedReader();
    PipedWriter writer = new PipedWriter(reader);
    ReportTransformer transformer = new ReportTransformer(out, style, reader);
    Thread transformerThread = new Thread(transformer);
    transformerThread.start();
    final ClaimStatistic statistic = report(base, writer, pConfiguration);
    writer.flush();
    writer.close();
    transformerThread.join();
    return statistic;
}

From source file:org.lockss.util.TestStreamUtil.java

public void testReadCharShortRead() throws Exception {
    char[] snd1 = { '0', '1', 0, '3' };
    final int len = 12;
    final char[] buf = new char[len];
    PipedWriter outs = new PipedWriter();
    final Reader ins = new PipedReader(outs);
    final Exception[] ex = { null };
    final int[] res = { 0 };
    Thread th = new Thread() {
        public void run() {
            try {
                res[0] = StreamUtil.readChars(ins, buf, len);
                StreamUtil.readChars(ins, buf, len);
            } catch (IOException e) {
                ex[0] = e;// w w w.j  a v a2 s.c o  m
            }
        }
    };
    th.start();
    outs.write(snd1);
    outs.close();
    th.join();

    assertEquals(snd1.length, res[0]);
    assertEquals(null, ex[0]);
}

From source file:org.lockss.util.TestStreamUtil.java

public void testReadCharMultipleRead() throws Exception {
    char[] snd1 = { '0', '1', 0, '3' };
    char[] snd2 = { '4', '5', '6', '7', '8', '9', 'a', 'b' };
    char[] exp = { '0', '1', 0, '3', '4', '5', '6', '7', '8', '9', 'a', 'b' };
    final int len = exp.length;
    final char[] buf = new char[len];
    PipedWriter outs = new PipedWriter();
    final Reader ins = new PipedReader(outs);
    final Exception[] ex = { null };
    final int[] res = { 0 };
    Thread th = new Thread() {
        public void run() {
            try {
                res[0] = StreamUtil.readChars(ins, buf, len);
            } catch (IOException e) {
                ex[0] = e;//from ww w  . j  ava2 s.c o  m
            }
        }
    };
    th.start();
    outs.write(snd1);
    TimerUtil.guaranteedSleep(100);
    outs.write(snd2);
    outs.flush();
    th.join();

    assertEquals(exp, buf);
    assertEquals(len, res[0]);
    assertNull(ex[0]);
    outs.close();
}