Search in sources :

Example 71 with PipedInputStream

use of java.io.PipedInputStream in project flink by apache.

the class RecordITCase method setUp.

@Before
public void setUp() throws Exception {
    PipedInputStream pipedInput = new PipedInputStream(32 * 1024 * 1024);
    this.in = new DataInputViewStreamWrapper(pipedInput);
    this.out = new DataOutputViewStreamWrapper(new PipedOutputStream(pipedInput));
}
Also used : DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) Before(org.junit.Before)

Example 72 with PipedInputStream

use of java.io.PipedInputStream in project flink by apache.

the class RecordTest method setUp.

@Before
public void setUp() throws Exception {
    PipedInputStream pipeIn = new PipedInputStream(1024 * 1024);
    PipedOutputStream pipeOut = new PipedOutputStream(pipeIn);
    this.in = new DataInputViewStreamWrapper(pipeIn);
    this.out = new DataOutputViewStreamWrapper(pipeOut);
}
Also used : DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) Before(org.junit.Before)

Example 73 with PipedInputStream

use of java.io.PipedInputStream in project rest.li by linkedin.

the class TestByteString method testRead.

private void testRead(final boolean knownLength) throws IOException, InterruptedException, TimeoutException, ExecutionException {
    final int pipeBufSize = 1024;
    final PipedOutputStream pos = new PipedOutputStream();
    final PipedInputStream pis = new PipedInputStream(pos, pipeBufSize);
    // We use twice the size of the pipe buffer to ensure that the first read
    // will not get all bytes. We can't use more than twice the pipe buffer size
    // because that the reader would effectively fall behind and pos.write(bytes)
    // would block.
    final byte[] bytes = new byte[2 * pipeBufSize];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (byte) (i % 256);
    }
    final ExecutorService exec = Executors.newSingleThreadExecutor();
    try {
        final Future<ByteString> result = exec.submit(new Callable<ByteString>() {

            @Override
            public ByteString call() throws Exception {
                return knownLength ? ByteString.read(pis, bytes.length) : ByteString.read(pis);
            }
        });
        pos.write(bytes);
        pos.close();
        Assert.assertEquals(result.get(60, TimeUnit.SECONDS).copyBytes(), bytes);
    } finally {
        exec.shutdownNow();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 74 with PipedInputStream

use of java.io.PipedInputStream in project j2objc by google.

the class InterruptedStreamTest method testInterruptPipedInputStream.

public void testInterruptPipedInputStream() throws Exception {
    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream(out);
    testInterruptInputStream(in);
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 75 with PipedInputStream

use of java.io.PipedInputStream in project j2objc by google.

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)

Aggregations

PipedInputStream (java.io.PipedInputStream)128 PipedOutputStream (java.io.PipedOutputStream)121 IOException (java.io.IOException)42 Test (org.junit.Test)33 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 DataInputStream (java.io.DataInputStream)13 DataOutputStream (java.io.DataOutputStream)13 InputStream (java.io.InputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Before (org.junit.Before)10 OutputStream (java.io.OutputStream)9 PrintStream (java.io.PrintStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStreamReader (java.io.InputStreamReader)6 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)5