avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gaurav <gaurav...@gmail.com>
Subject Decode without using DataFileReader
Date Mon, 05 Dec 2011 15:33:03 GMT
Hi,

I am trying to read byte stream of encoded data, which is coming from some
source but File. So I should not use DataFileReader. 

I wrote following code to do that, but here I have to specify schema on my
own, which ideally should come from data itself. Is there any other way to
get decode data with explicitly specifying schema and without using
DataFileReader?
----------------------
	private static void DecodeData(byte[] buf) throws IOException {
		// TODO Auto-generated method stub
		Schema schema = createSchema();
		GenericDatumReader<GenericData.Record> datum = new
GenericDatumReader<GenericData.Record>(schema);		
		
		ByteArrayInputStream in = new ByteArrayInputStream(buf);
		BinaryDecoder decoder = DECODER_FACTORY.binaryDecoder(in, null);
		
		GenericData.Record record = new GenericData.Record(datum.getSchema());
		datum.read(record, decoder);
		
		System.out.println(record.get("trade"));
	}
---------------------

Thanks,
Gaurav Nanda

--
View this message in context: http://apache-avro.679487.n3.nabble.com/Decode-without-using-DataFileReader-tp3561722p3561722.html
Sent from the Avro - Users mailing list archive at Nabble.com.

Mime
View raw message