Example usage for java.io PipedWriter flush

List of usage examples for java.io PipedWriter flush

Introduction

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

Prototype

public synchronized void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output characters to be written out.

Usage

From source file:Main.java

public static void main(String[] args) {

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

    try {//  ww  w.  j a  v  a 2s.co  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();
    }

}

From source file:org.apache.rat.Report.java

/**
 * /* w ww .  j a v a  2  s .com*/
 * 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 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   www . ja  va2 s . co  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();
}