You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by si...@gmail.com on 2011/03/19 01:53:16 UTC

reading bytes from a ByteBuffer

I have a large sequence of pdfs stored in an avro file as part of a larger structure.

I have found a bug in my code where I was calling

   byteBuffer.array() to get back the byte[], this is incorrect as this is entire backing store and NOT the contents of the element stored in Avro.

How/where do I get the offset and the length of the ByteBuffer returned from Avro? Ideally I would like a byte[] of the "bytes" stored in Avro.

The convenience classes were generated via the maven plugin so my Record signature is

	MyRecord extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord

The avro schema entry is

{
	"name" : "pdfs",
	"type" :  {  "type" : "array", "items": "bytes" }
}

Re: reading bytes from a ByteBuffer

Posted by Garrett Wu <wu...@gmail.com>.
byteBuffer.position() and byteBuffer.limit() are the start/end offsets in
the byteBuffer.array().

On Fri, Mar 18, 2011 at 5:53 PM, <si...@gmail.com> wrote:

> I have a large sequence of pdfs stored in an avro file as part of a larger
> structure.
>
> I have found a bug in my code where I was calling
>
>   byteBuffer.array() to get back the byte[], this is incorrect as this is
> entire backing store and NOT the contents of the element stored in Avro.
>
> How/where do I get the offset and the length of the ByteBuffer returned
> from Avro? Ideally I would like a byte[] of the "bytes" stored in Avro.
>
> The convenience classes were generated via the maven plugin so my Record
> signature is
>
>        MyRecord extends org.apache.avro.specific.SpecificRecordBase
> implements org.apache.avro.specific.SpecificRecord
>
> The avro schema entry is
>
> {
>        "name" : "pdfs",
>        "type" :  {  "type" : "array", "items": "bytes" }
> }