use of java.io.PipedOutputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testString.
@Test
public void testString() throws UnsupportedTypeException, IOException {
TypeToken<String> type = new TypeToken<String>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<String> writer = getWriter(type);
writer.encode("Testing message", new BinaryEncoder(os));
ReflectionDatumReader<String> reader = new ReflectionDatumReader<>(getSchema(type), type);
String value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals("Testing message", value);
}
use of java.io.PipedOutputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testRecord.
@Test
public void testRecord() 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(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.assertEquals(writeValue, value);
}
use of java.io.PipedOutputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testTree.
@Test
public void testTree() throws IOException, UnsupportedTypeException {
TypeToken<Node> type = new TypeToken<Node>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Node> writer = getWriter(type);
Node root = new Node((short) 1, new Node((short) 2, null, new Node((short) 3, null, null)), new Node((short) 4, new Node((short) 5, null, null), null));
writer.encode(root, new BinaryEncoder(os));
ReflectionDatumReader<Node> reader = new ReflectionDatumReader<>(getSchema(type), type);
Node value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(root, value);
}
use of java.io.PipedOutputStream in project cdap by caskdata.
the class ASMDatumCodecTest method testEnum.
@Test
public void testEnum() throws UnsupportedTypeException, IOException {
TypeToken<TestEnum> type = new TypeToken<TestEnum>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<TestEnum> writer = getWriter(type);
BinaryEncoder encoder = new BinaryEncoder(os);
writer.encode(TestEnum.VALUE1, encoder);
writer.encode(TestEnum.VALUE4, encoder);
writer.encode(TestEnum.VALUE3, encoder);
ReflectionDatumReader<TestEnum> reader = new ReflectionDatumReader<>(getSchema(type), type);
TestEnum value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(TestEnum.VALUE1, value);
value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(TestEnum.VALUE4, value);
value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(TestEnum.VALUE3, value);
}
use of java.io.PipedOutputStream 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);
}
Aggregations