Hello,

I'm currently trying to port a Java JRE6 program into Google Android
platform. This program uses NIO buffers to read data from a binary
file. It needs to read byte and short from the file.

With standard JRE6, I could "navigate" throught the memory mapped data
using thoses kind of code :

final FileInputStream fis = ....
final FileChannel channel = fis.getChannel();
byteBuffer = channel.map(MapMode.READ_ONLY, 0, channel.size());

// Read some bytes.
byteBuffer.get();
byteBuffer.get(array);

OK, this seems to work well too on Google Android. But problems start
to happen when I need to read short values after reading byte values
from the buffer.

When, in JRE6 platform, I do :

// Read a short value
byteBuffer.asShortBuffer().get();

I successfully retrieve the first short value at the corresponding
position from byteBuffer. Eg, if byteBuffer is at position 10, then it
reads two bytes (pos 11 and 12) and computes then as a short. That's
the standard functionnality.

But with Google Android, it doesn't seem to work that way. The same
code doesn't produce the same output :

// Read a short value
byteBuffer.asShortBuffer().get();

The "byteBuffer.asShortBuffer()" successfully returns a ShortBuffer,
but position seems to be lost in the creation of the ShortBuffer. Eg,
if position in byteBuffer was 10, the position of ShortBuffer is
actually 0. So when I read a short value from this ShortBuffer, it
actually read the two first bytes of the stream (0 and 1) instead of
reading bytes at position 11 and 12 as the normal JRE6 does.

Thus, each time I want to read a short value, either I must use the
ByteBuffer and computes by myself two bytes into one short, either I
use the "asShortBuffer" method but then I have to compute myself the
right position into the new buffer, thing I didn't have to make with
JRE6.

Is that a bug or a normal thing with Android ?
Thanks for your help,
Mikael

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to