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));
}
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);
}
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();
}
}
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);
}
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);
}
}
Aggregations