How long does it take to just copy from a byte[] to your own char[] in code?

On Tue, Sep 1, 2009 at 5:13 PM, WoodManEXP <[email protected]> wrote:

>
> 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!
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
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