use of java.io.PipedInputStream 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.PipedInputStream in project cdap by caskdata.
the class RecordWithString method testReduceProjection.
@Test
public void testReduceProjection() throws IOException, UnsupportedTypeException {
PipedOutputStream output = new PipedOutputStream();
PipedInputStream input = new PipedInputStream(output);
Schema sourceSchema = new ReflectionSchemaGenerator().generate(MoreFields.class);
Schema targetSchema = new ReflectionSchemaGenerator().generate(LessFields.class);
MoreFields moreFields = new MoreFields(10, 20.2, "30", ImmutableList.of("1", "2"));
new ReflectionDatumWriter<MoreFields>(sourceSchema).encode(moreFields, new BinaryEncoder(output));
LessFields lessFields = new ReflectionDatumReader<>(targetSchema, TypeToken.of(LessFields.class)).read(new BinaryDecoder(input), sourceSchema);
Assert.assertEquals("30", lessFields.k);
Assert.assertEquals(moreFields.inner.b, lessFields.inner.b);
}
use of java.io.PipedInputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testMap.
@Test
public void testMap() throws IOException, UnsupportedTypeException {
TypeToken<Map<String, List<String>>> type = new TypeToken<Map<String, List<String>>>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Map<String, List<String>>> writer = getWriter(type);
ImmutableMap<String, List<String>> map = ImmutableMap.<String, List<String>>of("k1", Lists.newArrayList("v1"), "k2", Lists.newArrayList("v2", null));
writer.encode(map, new BinaryEncoder(os));
ReflectionDatumReader<Map<String, List<String>>> reader = new ReflectionDatumReader<>(getSchema(type), type);
Assert.assertEquals(map, reader.read(new BinaryDecoder(is), getSchema(type)));
}
use of java.io.PipedInputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testReferenceArray.
@Test
public void testReferenceArray() throws IOException, UnsupportedTypeException {
TypeToken<String[]> type = new TypeToken<String[]>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
String[] writeValue = new String[] { "1", "2", null, "3" };
DatumWriter<String[]> writer = getWriter(type);
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<String[]> reader = new ReflectionDatumReader<>(getSchema(type), type);
String[] value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertArrayEquals(writeValue, value);
}
use of java.io.PipedInputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testRecordArray.
@Test
public void testRecordArray() throws IOException, UnsupportedTypeException {
TypeToken<Record[][]> type = new TypeToken<Record[][]>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Record[][]> writer = getWriter(type);
Record[][] writeValue = new Record[][] { { new Record(10, "testing", ImmutableList.of("a", "b", "c"), TestEnum.VALUE2) } };
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<Record[][]> reader = new ReflectionDatumReader<>(getSchema(type), type);
Record[][] value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertArrayEquals(writeValue, value);
}
Aggregations