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 = new byte[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
}
}
|