Similar past experience here - As trivial as it seems it's a buster in Java. Copying over a byte at a time is a way out that I've used in the past - on the server side, and it's a solution that leaves that sense of guilt of wasting resources. Not having tried this, I'd venture to see if the I/O stuff can be covered with the NDK. The relevant function would have to include a Java binding that provides that typecast of the underlying data to a Java char[].
On Sep 1, 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! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

