|
From: Arno P. <ar...@pu...> - 2012-03-28 17:22:50
|
I think that code is correct. If you look at the documentation of
InputStream.read(byte[]) you will see that if will read at most the
length of the array. That is that the i == READ_BUF_SIZE is for: it
indicates that there is potentially more data to be read.
But to mention something else: the code you are referring to is the Java
implementation of class NSData. This code belongs to XMLVM's Java
emulator for iOS (meaning you can run a Java-based iOS application on a
JVM). That was more an experiment and we stopped adding functionality a
long time ago because we would have to re-implement iOS in Java (which
is clearly out of scope). Note that that Java implementation you are
seeing is *not* used during cross-compilation.
Arno
On 3/25/12 10:36 PM, Tim Christensen wrote:
> Hi,
>
> I am trying to consume a JSON response, however, NSData byte array size
> is only 26. I saw there was an earlier discussion about this, but no
> resolution.
>
> When reviewing the code I see this logic:
>
> do {
> byte[] buf = new byte[READ_BUF_SIZE];
> i = in.read(buf);
>
> if (i > 0) {
> l.add(buf);
> bytesRead += i;
> }
>
>
> } while (i == READ_BUF_SIZE);
>
> How is it possible that (i == READ_BUF_SIZE)? In other words read the
> input stream while i = 32767 - this will end after the first try. I can
> see that my InputStream does contain all of the data but the readData
> method only returns a 26 character portion.
>
> I am fixing this for my own immediate needs but in the meantime I wanted
> to understand if I was missing something since I would assume this to be
> a fundamental need for a lot of apps???
>
> Here is my fix for the time being:
>
> private void readData(InputStream in) {
> data= newbyte[READ_BUF_SIZE];
>
>
> try {
> int offset = 0;
> int numRead = 0;
>
>
> while (offset < data.length && (numRead=in.read(data, offset,
> data.length-offset)) >= 0)
> {
> offset += numRead;
> }
>
> in.close();
> } catch (IOException ex) {
> // Do nothing
> }
> }
>
>
>
>
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
>
>
>
> _______________________________________________
> xmlvm-users mailing list
> xml...@li...
> https://lists.sourceforge.net/lists/listinfo/xmlvm-users
|