Home > Default > Dropped data in SAXParser client xml over http

Dropped data in SAXParser client xml over http

October 11Hits:1
Hi all, I need some expert help.
I have succeeded in getting our server to encode small gif image files using base64, and transmitting the resulting text in XML back to a client using SAXParser via http. The client overrides characters(char[] ch, int start, int length) in the content handler and decodes the text back to bytes, then reconstructs the gif file and displays it in the client GUI.
Now I've moved on to some extremely large images and am running into problems. The server still appears to encode the image correctly. For this test image the server sends 886 character buffers 200 bytes long and 1 buffer 168 bytes long for a total of 887 buffers and 177368 characters, generated from 133026 bytes.
My client parses the HttpURLConnection InputStream and parses it using SAXParser. The content handler characters() method handles 887 char[] reads. I would expect the first 886 times for the length argument in characters() to be 200 and the last to be 168, exactly like what the server generated, but there are a few intermittent times when length is less than 200. Some data has been lost.
Does something need to be flushed on the server side that could be causing this? The server creates a Writer from the HttpURLConnection outputstream and writes to the writer each time a buffer of bytes has been decoded, like so:
char[] cdata = Base64.encode(bdata);
// bdata.length = 150, cdata.length = 200
Or does the HttpURLConnection inputstream on the client side need to be wrapped in a particular input stream or stream reader? I've tried:
parser.parse(new InputSource(new BufferedReader(new InputStreamReader(urlconn.getInputStream()))));
I'm using Apache's Xerces 1.3.0, by the way.


The cure appears to be to use a raw input stream. Do NOT wrap the input stream in any kind of reader!
In other words, do this:
parser.parse(new InputSource(conn.getInputStream()));
But do NOT do this:
parser.parse(new InputSource(new InputStreamReader(conn.getInputStream())));

Read other 3 answers


Related Articles

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.534 s.