use of org.spf4j.demo.avro.DemoRecordInfo in project spf4j by zolyfarkas.
the class CsvEncoderTest method testEncodeDecodeSpecific.
@Test
public void testEncodeDecodeSpecific() throws IOException, CsvParseException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Schema aSchema = Schema.createArray(DemoRecordInfo.SCHEMA$);
CsvEncoder csvEncoder = new CsvEncoder(Csv.CSV.writer(new OutputStreamWriter(bos, StandardCharsets.UTF_8)), aSchema);
csvEncoder.writeHeader();
DatumWriter writer = new GenericDatumWriter(aSchema);
List<DemoRecordInfo> testRecords = testRecords();
writer.write(testRecords, csvEncoder);
csvEncoder.flush();
LOG.debug("serialized", bos.toString("UTF8"));
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
DecodedSchema ds = CsvDecoder.tryDecodeSchema(bis, aSchema);
Decoder decoder = ds.getDecoder();
SpecificDatumReader reader = new SpecificDatumReader(ds.getSchema());
Object read = reader.read(reader, decoder);
LOG.debug("deserialized", read);
Assert.assertEquals(testRecords, read);
}
Aggregations