use of org.apache.avro.io.BinaryEncoder in project core by s4.
the class AvroSerDeser method serialize.
public static byte[] serialize(Schema schema, GenericRecord content) throws IOException {
GenericDatumWriter<GenericRecord> serveWriter = new GenericDatumWriter<GenericRecord>(schema);
ByteArrayOutputStream out = new ByteArrayOutputStream();
serveWriter.write(content, new BinaryEncoder(out));
return out.toByteArray();
}
use of org.apache.avro.io.BinaryEncoder in project core by s4.
the class AvroUtils method serialize.
public static byte[] serialize(Schema schema, GenericRecord content) throws Exception {
GenericDatumWriter<GenericRecord> serveWriter = new GenericDatumWriter<GenericRecord>(schema);
ByteArrayOutputStream out = new ByteArrayOutputStream();
serveWriter.write(content, new BinaryEncoder(out));
return out.toByteArray();
}
use of org.apache.avro.io.BinaryEncoder in project voldemort by voldemort.
the class AvroGenericSerializer method toBytes.
public byte[] toBytes(Object object) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Encoder encoder = new BinaryEncoder(output);
GenericDatumWriter<Object> datumWriter = null;
try {
datumWriter = new GenericDatumWriter<Object>(typeDef);
datumWriter.write(object, encoder);
encoder.flush();
} catch (IOException e) {
throw new SerializationException(e);
} finally {
SerializationUtils.close(output);
}
return output.toByteArray();
}
use of org.apache.avro.io.BinaryEncoder in project voldemort by voldemort.
the class AvroSpecificSerializer method toBytes.
public byte[] toBytes(T object) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Encoder encoder = new BinaryEncoder(output);
SpecificDatumWriter<T> datumWriter = null;
try {
datumWriter = new SpecificDatumWriter<T>(clazz);
datumWriter.write(object, encoder);
encoder.flush();
} catch (IOException e) {
throw new SerializationException(e);
} finally {
SerializationUtils.close(output);
}
return output.toByteArray();
}
use of org.apache.avro.io.BinaryEncoder in project eiger by wlloyd.
the class SerDeUtils method serialize.
/**
* Serializes a single object.
* @param o Object to serialize
*/
public static <T extends SpecificRecord> ByteBuffer serialize(T o) throws IOException {
OutputBuffer buff = new OutputBuffer();
BinaryEncoder enc = new BinaryEncoder(buff);
SpecificDatumWriter<T> writer = new SpecificDatumWriter<T>(o.getSchema());
writer.write(o, enc);
enc.flush();
return ByteBuffer.wrap(buff.asByteArray());
}
Aggregations