Hi,
I'm facing a performance issue with reading an XML document from a URLConnection. The relevant piece of code is as follows:
StringBuffer xmlResponse = new StringBuffer();
URLConnection conn = url.openConnection();
conn.connect();
InputStream streamIn = conn.getInputStream();
System.out.println("Start Time is " + new Date());
if (streamIn != null) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(streamIn));
String line = null;
while ((line = reader.readLine()) != null) {
xmlResponse.append(line);
}
}
System.out.println("End Time is " + new Date());
It takes 4 to 5 seconds for the code beginning at the if condition to complete. The XML document getting streamed from the URL is around 800 KB. The question is why does it take 4 to 5 seconds to stream the data into the String Buffer. I tried a few alternatives like
using the read() method to read the data into a byte array and then append it to the StringBuffer but I got the same delay of 4 to 5 secs. Since the XML document will be parsed after streamig and be used to populate the front end screen, response time matters.
Any ideas?