I have an avro schema. While compiling it, the model class comes into existence in Java, let’s call it Test1 class.
When serializing the Test instances like this:
Test1 test1.getEncoder().encode();
it generates a byte stream that is a bit longer then the byte stream generated by
private void serialiseToByteStream(Test1 test1) throws IOException {
byte[] bytes = null;
try {
if (test1 != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BinaryEncoder binaryEncoder = EncoderFactory.get().binaryEncoder(byteArrayOutputStream, null);
DatumWriter<Test1> notizDatumWriter = new SpecificDatumWriter<Test1>(Test1.class);
notizDatumWriter.write(test1, binaryEncoder);
binaryEncoder.flush();
byteArrayOutputStream.close();
bytes = byteArrayOutputStream.toByteArray();
LOGGER.info("serialized Test1 object ='{}'", DatatypeConverter.printHexBinary(bytes));
Files.write(Paths.get("path/to/file"), bytes);
}
} catch (Exception e) {
LOGGER.error("Unable to serialize ", e);
}
}
The byte stream created by the encode() method seems to have a prefix compared to the byte stream produced by the SpecificDatumWriter. I cannot find any documentation that would define this. Can I cut off this prefix somehow from the byte stream while producing it with the encode()?