This is sort of a java question too…

How to read in a large array of chars, quickly?

I have a file on the /sdcard/ with a million chars (2 bytes each) that
I would like to read in quickly. It is a binary file written from
another system and I cannot change it.

It can be read into a byte[] array extremely quickly with a statement
like

// dInStream is an open DataInoutStream
// This is a really, really fast operation on Android
byte[] rBuffer = new byte[2*1000000]; // Yes I know this is a lot for
Android
numBytesRead = dInStream.read(rBuffer, 0, 2*1000000);

But then to get the data into a char[] array is evading me.

I have tried lots of stuff from java.nio like ByteBuffers converting
to CharBuffers and the get methods and they will do the conversion but
they are so very S L O W.

It takes < 1 sec to do the dInStream.read call and then like 30
seconds to walk over the wraped ByteArray.asCharBuffer using the
various get methods.

For a sec I thought ByteBuffer.asCharBuffer.array() was going to save
the day. But it exceptions out because the wrap of the byte[] array is
owned by the ByteBuffer, not the CharBuffer.

Is there any way just to do the dInStream.read directly into the char
array or maybe “cast” the byte[] array to a char[] array?

Thanks in advance for any help!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
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