use of java.io.PipedOutputStream in project robovm by robovm.
the class OldBufferedReaderTest method test_8778372.
public void test_8778372() throws Exception {
final PipedInputStream pis = new PipedInputStream();
final PipedOutputStream pos = new PipedOutputStream(pis);
final Thread t = new Thread() {
@Override
public void run() {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(pos));
pw.print("hello, world\r");
pw.flush();
try {
Thread.sleep(2 * 60 * 1000);
} catch (InterruptedException ex) {
fail();
}
}
};
t.start();
BufferedReader br = new BufferedReader(new InputStreamReader(pis));
assertEquals("hello, world", br.readLine());
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class DeflaterOutputStreamTest method createInflaterStream.
/**
* Creates an optionally-flushing deflater stream, writes some bytes to it,
* and flushes it. Returns an inflater stream that reads this deflater's
* output.
*
* <p>These bytes are written on a separate thread so that when the inflater
* stream is read, that read will fail when no bytes are available. Failing
* takes 3 seconds, co-ordinated by PipedInputStream's 'broken pipe'
* timeout. The 3 second delay is unfortunate but seems to be the easiest
* way demonstrate that data is unavailable. Ie. other techniques will cause
* the dry read to block indefinitely.
*/
static InputStream createInflaterStream(final Class<?> c, final boolean flushing) throws Exception {
ExecutorService executor = Executors.newSingleThreadExecutor();
final PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
executor.submit(new Callable<Void>() {
public Void call() throws Exception {
OutputStream out;
if (c == DeflaterOutputStream.class) {
out = new DeflaterOutputStream(pout, flushing);
} else if (c == GZIPOutputStream.class) {
out = new GZIPOutputStream(pout, flushing);
} else {
throw new AssertionError();
}
out.write(1);
out.write(2);
out.write(3);
out.flush();
return null;
}
}).get();
executor.shutdown();
if (c == DeflaterOutputStream.class) {
return new InflaterInputStream(pin);
} else if (c == GZIPOutputStream.class) {
return new GZIPInputStream(pin);
} else {
throw new AssertionError();
}
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class Test method test_readObject_replacedClassDescriptor.
// Regression test for HARMONY-4996
public void test_readObject_replacedClassDescriptor() throws Exception {
ObjectStreamClass[] objs = new ObjectStreamClass[1000];
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
ObjectOutputStream oout = new TestObjectOutputStream(pout, objs);
oout.writeObject(new TestExtObject());
oout.writeObject("test");
oout.close();
ObjectInputStream oin = new TestObjectInputStream(pin, objs);
oin.readObject();
oin.readObject();
}
use of java.io.PipedOutputStream in project robovm by robovm.
the class Test method test_readClassDescriptor_1.
/*
* Testing classDescriptor replacement with the value generated by
* ObjectStreamClass.lookup() method.
* Regression test for HARMONY-4638
*/
public void test_readClassDescriptor_1() throws IOException, ClassNotFoundException {
A a = new A();
a.name = "It's a test";
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
ObjectOutputStream out = new ObjectOutputStream(pout);
ObjectInputStream in = new ObjectIutputStreamWithReadDesc2(pin, A.class);
// test single object
out.writeObject(a);
A a1 = (A) in.readObject();
assertEquals("Single case: incorrectly read the field of A", a.name, a1.name);
// test cyclic reference
HashMap m = new HashMap();
a = new A();
a.name = "It's a test 0";
a1 = new A();
a1.name = "It's a test 1";
m.put("0", a);
m.put("1", a1);
out.writeObject(m);
HashMap m1 = (HashMap) in.readObject();
assertEquals("Incorrectly read the field of A", a.name, ((A) m1.get("0")).name);
assertEquals("Incorrectly read the field of A1", a1.name, ((A) m1.get("1")).name);
}
use of java.io.PipedOutputStream in project jedis by xetorthio.
the class ProtocolTest method buildACommand.
@Test
public void buildACommand() throws IOException {
PipedInputStream pis = new PipedInputStream();
BufferedInputStream bis = new BufferedInputStream(pis);
PipedOutputStream pos = new PipedOutputStream(pis);
RedisOutputStream ros = new RedisOutputStream(pos);
Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
ros.flush();
pos.close();
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
int b;
StringBuilder sb = new StringBuilder();
while ((b = bis.read()) != -1) {
sb.append((char) b);
}
assertEquals(expectedCommand, sb.toString());
}
Aggregations