use of org.apache.avro.io.Decoder in project voldemort by voldemort.
the class AvroGenericSerializer method toObject.
public Object toObject(byte[] bytes) {
Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
GenericDatumReader<Object> reader = null;
try {
reader = new GenericDatumReader<Object>(typeDef);
return reader.read(null, decoder);
} catch (IOException e) {
throw new SerializationException(e);
}
}
use of org.apache.avro.io.Decoder in project voldemort by voldemort.
the class AvroReflectiveSerializer method toObject.
public T toObject(byte[] bytes) {
Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
ReflectDatumReader<T> reader = null;
try {
reader = new ReflectDatumReader<T>(clazz);
return reader.read(null, decoder);
} catch (IOException e) {
throw new SerializationException(e);
}
}
use of org.apache.avro.io.Decoder 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);
}
}
use of org.apache.avro.io.Decoder in project cdap by caskdata.
the class FetchHandler method poll.
@POST
@Path("poll")
public void poll(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
TopicId topicId = new NamespaceId(namespace).topic(topic);
// Currently only support avro
if (!"avro/binary".equals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE))) {
throw new BadRequestException("Only avro/binary content type is supported.");
}
// Decode the poll request
Decoder decoder = DecoderFactory.get().directBinaryDecoder(new ChannelBufferInputStream(request.getContent()), null);
DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(Schemas.V1.ConsumeRequest.SCHEMA);
// Fetch the messages
CloseableIterator<RawMessage> iterator = fetchMessages(datumReader.read(null, decoder), topicId);
try {
responder.sendContent(HttpResponseStatus.OK, new MessagesBodyProducer(iterator, messageChunkSize), ImmutableMultimap.of(HttpHeaders.Names.CONTENT_TYPE, "avro/binary"));
} catch (Throwable t) {
iterator.close();
throw t;
}
}
use of org.apache.avro.io.Decoder in project cdap by caskdata.
the class StoreHandler method createStoreRequest.
/**
* Creates a {@link StoreRequest} instance based on the given {@link HttpRequest}.
*/
private StoreRequest createStoreRequest(TopicId topicId, HttpRequest request) throws Exception {
// Currently only support avro
if (!"avro/binary".equals(request.getHeader(HttpHeaders.Names.CONTENT_TYPE))) {
throw new BadRequestException("Only avro/binary content type is supported.");
}
Decoder decoder = DecoderFactory.get().directBinaryDecoder(new ChannelBufferInputStream(request.getContent()), null);
DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(Schemas.V1.PublishRequest.SCHEMA);
return new GenericRecordStoreRequest(topicId, datumReader.read(null, decoder));
}
Aggregations