Search in sources :

Example 21 with SerializationException

use of voldemort.serialization.SerializationException in project voldemort by voldemort.

the class AvroSpecificSerializer method toObject.

public T toObject(byte[] bytes) {
    Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
    SpecificDatumReader<T> reader = null;
    try {
        reader = new SpecificDatumReader<T>(clazz);
        return reader.read(null, decoder);
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}
Also used : SerializationException(voldemort.serialization.SerializationException) IOException(java.io.IOException) Decoder(org.apache.avro.io.Decoder)

Example 22 with SerializationException

use of voldemort.serialization.SerializationException 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)

Aggregations

SerializationException (voldemort.serialization.SerializationException)22 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 BinaryEncoder (org.apache.avro.io.BinaryEncoder)5 Encoder (org.apache.avro.io.Encoder)5 Decoder (org.apache.avro.io.Decoder)4 Schema (org.apache.avro.Schema)3 ByteArray (voldemort.utils.ByteArray)3 Versioned (voldemort.versioning.Versioned)3 BufferedWriter (java.io.BufferedWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TException (org.apache.thrift.TException)2 TProtocol (org.apache.thrift.protocol.TProtocol)2 Node (voldemort.cluster.Node)2 Serializer (voldemort.serialization.Serializer)2 SerializerDefinition (voldemort.serialization.SerializerDefinition)2