Skip to main content
June 16, 2011
Answered

Bug in byteArray 's method readBytes

  • June 16, 2011
  • 1 reply
  • 924 views

Hi

When I use readBytes ie. like this:

data.readBytes(chunkData, 16, 4);

I get 20 bytes not the 4 I requested (chunkData.length = 20 not 4).

This topic has been closed for replies.
Correct answer

The second argument is the offset of the destination ByteArray.

You are reading 4 bytes from the source (data) and inserting those 4 bytes at offset 16 of chunkData - therefore chunkData.length is 20;

1 reply

Correct answer
June 16, 2011

The second argument is the offset of the destination ByteArray.

You are reading 4 bytes from the source (data) and inserting those 4 bytes at offset 16 of chunkData - therefore chunkData.length is 20;

June 16, 2011

Ok so if I want to read from the 16 to the 20, what to do?

Where does it start reading from? data.position or 0?

It is a bit wird that the offset is where the data is written in the new bytearray not where it starts reading from.

June 16, 2011

data.position=16;

data.readBytes(chunkData, 0, 4);

Once executed data.position will be 20 and chunkData will have 4 bytes.