Search in sources :

Example 21 with BinaryEncoder

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();
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 22 with BinaryEncoder

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();
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 23 with BinaryEncoder

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();
}
Also used : SerializationException(voldemort.serialization.SerializationException) BinaryEncoder(org.apache.avro.io.BinaryEncoder) BinaryEncoder(org.apache.avro.io.BinaryEncoder) Encoder(org.apache.avro.io.Encoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 24 with BinaryEncoder

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();
}
Also used : SerializationException(voldemort.serialization.SerializationException) BinaryEncoder(org.apache.avro.io.BinaryEncoder) BinaryEncoder(org.apache.avro.io.BinaryEncoder) Encoder(org.apache.avro.io.Encoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 25 with BinaryEncoder

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());
}
Also used : BinaryEncoder(org.apache.avro.io.BinaryEncoder) OutputBuffer(org.apache.cassandra.io.util.OutputBuffer) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter)

Aggregations

BinaryEncoder (org.apache.avro.io.BinaryEncoder)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)17 GenericRecord (org.apache.avro.generic.GenericRecord)17 IOException (java.io.IOException)14 Encoder (org.apache.avro.io.Encoder)10 SerializationException (voldemort.serialization.SerializationException)5 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)4 ArrayList (java.util.ArrayList)3 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 Producer (kafka.javaapi.producer.Producer)2 KeyedMessage (kafka.producer.KeyedMessage)2 ProducerConfig (kafka.producer.ProducerConfig)2 Schema (org.apache.avro.Schema)2 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)2 EncoderFactory (org.apache.avro.io.EncoderFactory)2 OutputBuffer (org.apache.cassandra.io.util.OutputBuffer)2 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)2