Example usage for java.io PipedOutputStream close

List of usage examples for java.io PipedOutputStream close

Introduction

In this page you can find the example usage for java.io PipedOutputStream 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) throws Exception {
    PipedInputStream in = new PipedInputStream(20);
    PipedOutputStream out = new PipedOutputStream(in);

    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    // create a new Piped input and Output Stream
    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

    // connect input and output
    out.connect(in);//  w  w  w.  j  av  a  2s. c  om

    // write something
    out.write(70);
    out.write(71);

    out.close();

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

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

    out.connect(in);//  w  ww. jav  a  2  s  .  com

    out.write(70);
    out.write(71);
    out.write(72);

    out.flush();

    for (int i = 0; i < 3; i++) {
        System.out.println((char) in.read());
    }
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

    out.connect(in);/*from w  w  w.j a  va  2s  .c o  m*/

    out.write(70);
    out.write(71);

    out.flush();

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

From source file:Main.java

public static void main(String[] args) throws Exception {

    byte[] b = { 'h', 'e', 'l', 'l', 'o' };

    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

    out.connect(in);/*from  w ww .  j  av  a 2s.co m*/

    // write something
    out.write(b, 0, 3);

    // flush the stream
    out.flush();

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

From source file:Main.java

public static void main(String[] args) throws Exception {

    PipedOutputStream out = new PipedOutputStream();
    Main in = new Main();

    // connect input and output
    out.connect(in);//from w  w w. jav a2s .  c om

    // write something
    out.write(70);
    out.write(71);

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

From source file:Main.java

public static void produceData(PipedOutputStream pos) {
    try {//  w w w  .j av a  2 s.com
        for (int i = 1; i <= 50; i++) {
            pos.write((byte) i);
            pos.flush();
            System.out.println("Writing: " + i);
            Thread.sleep(500);
        }
        pos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.hawkular.rest.ResponseUtil.java

private static <T> InputStream pageToStream(Page<T> page, ObjectMapper mapper, Runnable callback)
        throws IOException {
    final PipedOutputStream outs = new PipedOutputStream();
    final PipedInputStream ins = new PipedInputStream() {
        @Override//w ww . j a  va 2 s.com
        public void close() throws IOException {
            outs.close();
            super.close();
        }
    };
    outs.connect(ins);
    mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

    PageToStreamThreadPool.getInstance().submit(() -> {
        try (Page<T> closeablePage = page;
                PipedOutputStream out = outs;
                SequenceWriter sequenceWriter = mapper.writer().writeValuesAsArray(out)) {
            for (T element : closeablePage) {
                sequenceWriter.write(element);
                sequenceWriter.flush();
            }
        } catch (IOException e) {
            throw new IllegalStateException("Unable to convert page to input stream.", e);
        } finally {
            callback.run();
        }
    });
    return ins;
}

From source file:de.upb.wdqa.wdvd.FeatureExtractor.java

private static InputStream getPipedDumpFileStream(final InputStream inputStream) throws IOException {
    final PipedOutputStream pipedOutputStream = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream, BUFFER_SIZE);

    new Thread("Dump File Reader") {
        @Override/* w  ww. j  av a2s  .  c om*/
        public void run() {
            try {
                IOUtils.copy(inputStream, pipedOutputStream);

                inputStream.close();
                pipedOutputStream.close();
            } catch (Throwable t) {
                logger.error("", t);
            }
        }
    }.start();

    return pipedInputStream;
}

From source file:de.upb.wdqa.wdvd.FeatureExtractor.java

private static InputStream getUncompressedStream(final InputStream inputStream) throws IOException {
    // the decompression is a major bottleneck, make sure that it does not
    // have to wait for the buffer to empty
    final PipedOutputStream pipedOutputStream = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream, BUFFER_SIZE);

    new Thread("Dump File Decompressor") {
        @Override/*from ww w . j  a v a  2  s . c  o  m*/
        public void run() {
            try {
                InputStream compressorInputStream = new BZip2CompressorInputStream(inputStream);

                IOUtils.copy(compressorInputStream, pipedOutputStream);

                compressorInputStream.close();
                pipedOutputStream.close();
            } catch (IOException e) {
                logger.error("", e);
            }
        }
    }.start();

    return pipedInputStream;
}