Example usage for java.io PipedInputStream PipedInputStream

List of usage examples for java.io PipedInputStream PipedInputStream

Introduction

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

Prototype

public PipedInputStream() 

Source Link

Document

Creates a PipedInputStream so that it is not yet #connect(java.io.PipedOutputStream) connected .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pos.connect(pis);//w w w . j a va  2 s .c  om

    Runnable producer = () -> produceData(pos);
    Runnable consumer = () -> consumeData(pis);
    new Thread(producer).start();
    new Thread(consumer).start();
}

From source file:Main.java

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

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

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

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

From source file:Main.java

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

    // connect input and output
    in.connect(out);/*from   www .j  av  a2s .  c  o  m*/

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

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

}

From source file:Main.java

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

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

    // connect input and output
    in.connect(out);/*w  w w  .  j av a2s .co  m*/

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

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

From source file:Main.java

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

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

    // connect input and output
    in.connect(out);//  w  w w .  ja  v  a2s  . co  m

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

    // read what we wrote into an array of bytes
    byte[] b = new byte[2];
    in.read(b, 0, 2);

    System.out.println(new String(b));
    in.close();
}

From source file:Main.java

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

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

    // connect input and output
    in.connect(out);//from   w w w  .  jav a2  s .co m

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

    // print how many bytes are available
    System.out.println(in.available());

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

From source file:Pipe.java

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

    Sender s = new Sender(out);
    Receiver r = new Receiver(in);
    Thread t1 = new Thread(s);
    Thread t2 = new Thread(r);
    t1.start();// ww w. ja va 2 s  .c o  m
    t2.start();
}

From source file:org.eclipse.lyo.oslc.v3.sample.ETag.java

/**
 * Create an ETag value from a Jena model.
 *
 * @param m the model that represents the HTTP response body
 * @param lang the serialization language
 * @param base the base URI/*from   w  ww  . j a  va2  s .  co m*/
 * @return an ETag value
 * @throws IOException on I/O errors
 *
 * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19">HTTP 1.1: Section 14.19 - ETag</a>
 */
public static String generate(final Model m, final String lang, final String base) throws IOException {
    final PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    new Thread(new Runnable() {
        public void run() {
            m.write(out, lang, base);
            try {
                out.close();
            } catch (IOException e) {
                logger.error("Error creating MD5 hash of Model", e);
            }
        }
    }).start();

    return generate(in);
}

From source file:end2endtests.runner.ProcessRunner.java

public ProcessRunner(File workingDir, List<String> command) {
    this.workingDir = workingDir;
    this.command = command;

    try {//from w  ww .  ja  v a  2s . c o m
        PipedInputStream in = new PipedInputStream();
        toOutputWatcher = new LowLatencyPipedOutputStream(in);
        outputWatcher = new StreamWatcher(new InputStreamReader(in));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

public static ImageDescriptor bufferedToDescriptorOptimized(final BufferedImage image) throws IOException {
    final PipedOutputStream output = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream();
    output.connect(pipedInputStream);/* w  w  w  .  j  a v  a 2  s .  co m*/

    try {
        new Thread() {

            @Override
            public void run() {
                try {
                    ChartUtilities.writeBufferedImageAsPNG(output, image, false, 0);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }.start();
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
    }

    ImageData img = new ImageData(pipedInputStream);
    ImageDescriptor descriptor = ImageDescriptor.createFromImageData(img);
    return descriptor;
}