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(int pipeSize) 

Source Link

Document

Creates a PipedInputStream so that it is not yet #connect(java.io.PipedOutputStream) connected and uses the specified pipe size for the pipe's buffer.

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   w  w w . ja va2  s.co  m
}

From source file:Main.java

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

    PipedOutputStream out = new PipedOutputStream();

    PipedInputStream in = new PipedInputStream(out);
}

From source file:Main.java

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

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

    // connect input and output
    in.connect(out);/*from  w ww. j a  v  a2  s .  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:MainClass.java

public static void main(String[] args) throws IOException {
    PipedOutputStream pout = new PipedOutputStream();
    PipedInputStream pin = new PipedInputStream(pout);

    NumberProducer fw = new NumberProducer(pout, 20);
    NumberConsumer fr = new NumberConsumer(pin);
    fw.start();/*from w  w w  . java 2  s. c  om*/
    fr.start();
}

From source file:TestPipes.java

public static void main(String[] args) throws Exception {
    final PipedOutputStream pos = new PipedOutputStream();

    final PipedInputStream pis = new PipedInputStream(pos);

    Runnable runOutput = new Runnable() {
        public void run() {
            writeData(pos);//  w w w .  j av a  2  s.  com
        }
    };

    Thread outThread = new Thread(runOutput, "outThread");
    outThread.start();

    Runnable runInput = new Runnable() {
        public void run() {
            readData(pis);
        }
    };

    Thread inThread = new Thread(runInput, "inThread");
    inThread.start();
}

From source file:PipedBytes.java

public static void main(String[] args) {
    try {/*  w  ww  . j  a v  a2 s.  c  o m*/
        final PipedOutputStream out = new PipedOutputStream();

        final PipedInputStream in = new PipedInputStream(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:com.symbian.driver.engine.Utils.java

/**
 * @param aCmd//w w  w.j  a  v a 2 s.  c  o m
 * @param aFirstParameter
 * @param aSecondParameter
 * @return
 * @throws JStatException
 * @throws IOException
 * @throws TimeLimitExceededException
 */
public static final BufferedReader executeOnDevice(final int aCmd, final String aFirstParameter,
        final String aSecondParameter) throws JStatException, IOException, TimeLimitExceededException {
    PipedOutputStream lPipedOutputStream = new PipedOutputStream();
    PipedInputStream lPipedInputStream = new PipedInputStream(lPipedOutputStream);

    try {
        if (aFirstParameter == null && aSecondParameter == null) {
            new ExecuteOnDevice(aCmd).doTask(true, EngineTests.TIMEOUT, false);
        } else if (aFirstParameter != null && aSecondParameter == null) {
            new ExecuteOnDevice(aCmd, aFirstParameter).doTask(true, EngineTests.TIMEOUT, false);
        } else if (aFirstParameter != null && aSecondParameter != null) {
            new ExecuteOnDevice(aCmd, aFirstParameter, aSecondParameter).doTask(true, EngineTests.TIMEOUT,
                    false);
        }
    } catch (ParseException lParseException) {
        throw new IOException("Could not read transport. " + lParseException.getMessage());
    }

    BufferedReader lBufferedReader = new BufferedReader(new InputStreamReader(lPipedInputStream));
    //      lPipedInputStream.close();
    lPipedOutputStream.close();

    return lBufferedReader;
}

From source file:custom.SevenZFileExt.java

public InputStream getInputStream(final int bufferSize) {
    final PipedInputStream in = new PipedInputStream(bufferSize);
    try {//from  www. j  a va2 s . c  o  m
        final PipedOutputStream out = new PipedOutputStream(in);
        Thread thread = new Thread(() -> {
            try {
                byte[] buffer = new byte[bufferSize];
                int len = read(buffer);
                while (len > 0) {
                    try {
                        out.write(buffer, 0, len);
                        len = read(buffer);
                    } catch (Exception ex) {
                        LOGGER.error(ex.getMessage(), ex);
                    }
                }
                out.flush();
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            } finally {
                if (out != null) {
                    try {
                        out.close();
                    } catch (Exception ex) {
                        LOGGER.error(ex.getMessage(), ex);
                    }
                }
            }
        });
        thread.setName("GenerateInputStreamSeven7File");
        thread.start();
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return in;
}

From source file:com.orange.clara.cloud.servicedbdumper.filer.AbstractGzipGenericFiler.java

@Override
public void store(InputStream inputStream, String filename) throws IOException {
    PipedOutputStream outputPipe = new PipedOutputStream();
    PipedInputStream inputPipe = new PipedInputStream(outputPipe);
    gzipCompressing.gziptIt(inputStream, outputPipe);
    logger.debug("Gziping file ...");
    this.originalFiler.store(inputPipe, filename);
}

From source file:annis.visualizers.component.AbstractDotVisualizer.java

@Override
public ImagePanel createComponent(final VisualizerInput visInput, VisualizationToggle visToggle) {
    try {/*from  w  w  w . j  a v a2s .c o m*/

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

        new Thread(new Runnable() {
            @Override
            public void run() {
                writeOutput(visInput, out);
            }
        }).start();

        String fileName = "dotvis_" + new Random().nextInt(Integer.MAX_VALUE) + ".png";
        StreamResource resource = new StreamResource(new StreamResource.StreamSource() {

            @Override
            public InputStream getStream() {
                return in;
            }
        }, fileName);

        Embedded emb = new Embedded("", resource);
        emb.setMimeType("image/png");
        emb.setSizeFull();
        emb.setStandby("loading image");
        emb.setAlternateText("DOT graph visualization");
        return new ImagePanel(emb);

    } catch (IOException ex) {
        log.error(null, ex);
    }
    return new ImagePanel(new Embedded());
}