Example usage for java.io PipedOutputStream PipedOutputStream

List of usage examples for java.io PipedOutputStream PipedOutputStream

Introduction

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

Prototype

public PipedOutputStream() 

Source Link

Document

Creates a piped output stream that is not yet connected to a piped input stream.

Usage

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  ww . j  a  v a 2 s  . 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 {

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

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

    // 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 main(String[] args) throws Exception {
    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    pos.connect(pis);//from   w w  w .  j  a v  a  2s.  com

    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 {

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

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

    out.connect(in);/* w  ww .  j a v  a 2  s  .  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 {

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

    // connect input and output
    out.connect(in);//from   w  ww.  j a  va  2  s  . co  m

    // 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: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 .  j  a v a2  s .  c o  m
    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);/*www  .  ja va 2s .  c o  m*/
        }
    };

    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 {/*from   w w  w.  j  a  v  a2 s .  com*/
        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 . ja  v  a 2s . com
 * @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: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);
}