Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Performance of BufferedReader

843790Apr 28 2008 — edited May 6 2008
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2008
Added on Apr 28 2008
7 comments
181 views