Search in sources :

Example 6 with PipedOutputStream

use of java.io.PipedOutputStream in project che by eclipse.

the class JschSshProcess method start.

// todo how to manage disconnections due to network failures?
@Override
public void start(LineConsumer output) throws MachineException {
    try (PipedOutputStream pipedOS = new PipedOutputStream();
        PipedInputStream pipedIS = new PipedInputStream(pipedOS);
        BufferedReader outReader = new BufferedReader(new InputStreamReader(pipedIS))) {
        exec.setOutputStream(pipedOS);
        exec.setExtOutputStream(pipedOS);
        exec.connect();
        String outLine;
        while ((outLine = outReader.readLine()) != null) {
            output.writeLine(outLine);
        }
    } catch (IOException | JSchException e) {
        throw new MachineException("Ssh machine command execution error:" + e.getLocalizedMessage());
    } finally {
        exec.disconnect();
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) InputStreamReader(java.io.InputStreamReader) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) BufferedReader(java.io.BufferedReader) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 7 with PipedOutputStream

use of java.io.PipedOutputStream in project symmetric-ds by JumpMind.

the class InternalTransportManager method getPushTransport.

@Override
public IOutgoingWithResponseTransport getPushTransport(final Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
    final PipedOutputStream pushOs = new PipedOutputStream();
    final PipedInputStream pushIs = new PipedInputStream(pushOs);
    final PipedOutputStream respOs = new PipedOutputStream();
    final PipedInputStream respIs = new PipedInputStream(respOs);
    runAtClient(remote.getSyncUrl(), pushIs, respOs, new IClientRunnable() {

        public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
            // This should be basically what the push servlet does ...
            engine.getDataLoaderService().loadDataFromPush(local, pushIs, respOs);
        }
    });
    return new InternalOutgoingWithResponseTransport(pushOs, respIs);
}
Also used : PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException)

Example 8 with PipedOutputStream

use of java.io.PipedOutputStream in project jdk8u_jdk by JetBrains.

the class JarBackSlash method testJarList.

private static void testJarList(String jarFile) throws IOException {
    List<String> argList = new ArrayList<String>();
    argList.add("-tvf");
    argList.add(jarFile);
    argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
    String[] jarArgs = new String[argList.size()];
    jarArgs = argList.toArray(jarArgs);
    PipedOutputStream pipedOutput = new PipedOutputStream();
    PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
    PrintStream out = new PrintStream(pipedOutput);
    Main jarTool = new Main(out, System.err, "jar");
    if (!jarTool.run(jarArgs)) {
        fail("Could not list jar file.");
    }
    out.flush();
    check(pipedInput.available() > 0);
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Main(sun.tools.jar.Main)

Example 9 with PipedOutputStream

use of java.io.PipedOutputStream in project robovm by robovm.

the class OldAndroidPipedStreamTest method testA.

public void testA() throws Exception {
    final PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    assertEquals(0, in.available());
    TestThread reader, writer;
    reader = new TestThread() {

        Fibonacci fib = new Fibonacci();

        @Override
        public void runTest() throws Exception {
            int readInt;
            byte readByte;
            for (; ; ) {
                readInt = in.read();
                if (readInt == -1) {
                    return;
                }
                readByte = (byte) readInt;
                assertEquals(readByte, (byte) fib.next());
                countRead++;
            }
        }
    };
    reader.start();
    writer = new TestThread() {

        Fibonacci fib = new Fibonacci();

        @Override
        public void runTest() throws Exception {
            for (int i = 0; i < 2000; i++) {
                int toWrite = fib.next();
                out.write(toWrite);
            }
            out.close();
        }
    };
    writer.start();
    for (; ; ) {
        try {
            reader.join(60 * 1000);
            writer.join(1000);
            break;
        } catch (InterruptedException ex) {
        }
    }
    assertEquals(2000, reader.countRead);
    if (writer.exception != null) {
        throw new Exception(writer.exception);
    }
    if (reader.exception != null) {
        throw new Exception(reader.exception);
    }
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 10 with PipedOutputStream

use of java.io.PipedOutputStream in project robovm by robovm.

the class OldAndroidPipedStreamTest method testB.

public void testB() throws Exception {
    final PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    assertEquals(0, in.available());
    TestThread reader, writer;
    reader = new TestThread() {

        Fibonacci fib = new Fibonacci();

        @Override
        public void runTest() throws Exception {
            byte[] readBytes = new byte[5];
            int ret;
            for (; ; ) {
                int nread = 0;
                while (nread < 5) {
                    ret = in.read(readBytes, nread, readBytes.length - nread);
                    if (ret == -1) {
                        return;
                    }
                    nread += ret;
                }
                assertEquals(5, nread);
                int readInt = (((int) readBytes[0] & 0xff) << 24) | (((int) readBytes[1] & 0xff) << 16) | (((int) readBytes[2] & 0xff) << 8) | (((int) readBytes[3] & 0xff));
                assertEquals("Error at " + countRead, fib.next(), readInt);
                assertEquals("Error at " + countRead, 0, readBytes[4]);
                countRead++;
            }
        }
    };
    reader.start();
    writer = new TestThread() {

        Fibonacci fib = new Fibonacci();

        @Override
        public void runTest() throws Exception {
            byte[] writeBytes = new byte[5];
            for (int i = 0; i < 2000; i++) {
                int toWrite = fib.next();
                writeBytes[0] = (byte) (toWrite >> 24);
                writeBytes[1] = (byte) (toWrite >> 16);
                writeBytes[2] = (byte) (toWrite >> 8);
                writeBytes[3] = (byte) (toWrite);
                writeBytes[4] = 0;
                out.write(writeBytes, 0, writeBytes.length);
            }
            out.close();
        }
    };
    writer.start();
    for (; ; ) {
        try {
            reader.join(60 * 1000);
            writer.join(1000);
            break;
        } catch (InterruptedException ex) {
        }
    }
    if (reader.exception != null) {
        throw new Exception(reader.exception);
    }
    if (writer.exception != null) {
        throw new Exception(writer.exception);
    }
    assertEquals(2000, reader.countRead);
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Aggregations

PipedOutputStream (java.io.PipedOutputStream)227 PipedInputStream (java.io.PipedInputStream)204 IOException (java.io.IOException)91 Test (org.junit.Test)55 InputStream (java.io.InputStream)28 OutputStream (java.io.OutputStream)24 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 PrintStream (java.io.PrintStream)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)19 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 InputStreamReader (java.io.InputStreamReader)16 DataInputStream (java.io.DataInputStream)14 DataOutputStream (java.io.DataOutputStream)14 BufferedReader (java.io.BufferedReader)13 Before (org.junit.Before)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ExecutorService (java.util.concurrent.ExecutorService)8 ArrayList (java.util.ArrayList)7