ReflectDatumWriter<Object> writer = new ReflectDatumWriter<Object>(schema);
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (!blocking) {
writer.write(datum, EncoderFactory.get().directBinaryEncoder(out, null));
} else {
writer.write(datum, new EncoderFactory().configureBlockSize(64)
.blockingBinaryEncoder(out, null));
}
writer.write(datum, EncoderFactory.get().directBinaryEncoder(out, null));
byte[] data = out.toByteArray();