Results 1 to 10 of 10
- 06-21-2012, 06:22 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
BufferedReader.readLine() slow reading long line.
Good Afternoon,
I am interfacing with a web site using their XML API to retrieve data. Unfortunately - everything is coming down the pipe on a single line, and the code I'm using is text book - I think.
In some instances readLine() takes 22 seconds to execute, there must be a better way.Java Code:BufferedReader d = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String output = d.readLine();
Any ideas would be appreciated! :)
- 06-21-2012, 06:29 PM #2
Re: BufferedReader.readLine() slow reading long line.
Is 22 seconds a reasonable time for the number of bytes being read?everything is coming down the pipe on a single lineIf you don't understand my response, don't ignore it, ask a question.
- 06-21-2012, 06:32 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: BufferedReader.readLine() slow reading long line.
Yes, that is a good point. :)
I should have included that my goal was to show progress to the end user instead of one of those never ending progress bars.
Also,
urlConn.getContentLength() returned unknown length, so If i can't get the content size all of this is moot anyway. Is there another way to retrieve the size of the content?Last edited by sumarlidason; 06-21-2012 at 06:35 PM.
- 06-21-2012, 06:41 PM #4
Re: BufferedReader.readLine() slow reading long line.
Have the sender send the length.
If you don't understand my response, don't ignore it, ask a question.
- 06-21-2012, 06:57 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: BufferedReader.readLine() slow reading long line.
Lets say I could make that happen; I'd like a way to read ?2048? bytes from the stream at a time, then I could provide a pretty accurate progress bar for the end user.
- 06-21-2012, 07:17 PM #6
Re: BufferedReader.readLine() slow reading long line.
Look at the read() methods.I'd like a way to read ?2048? bytesIf you don't understand my response, don't ignore it, ask a question.
- 06-21-2012, 07:28 PM #7
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: BufferedReader.readLine() slow reading long line.
At first glance I thought that was my answer, but the implementation is a little different, the parameter off,
looks to be used as an offset into the char[] you supply, not an offset into the BufferedReader. The other read() only reads a single byte, and this doesn't seem like a good idea for several MB of data.off - Offset at which to start storing characters
Thank you for helping me.
- 06-21-2012, 07:33 PM #8
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: BufferedReader.readLine() slow reading long line.
Or - the buffered reader handles that internally like it does with read(). I'll give that a shot.
- 06-21-2012, 07:38 PM #9
Re: BufferedReader.readLine() slow reading long line.
Also look at the Reader class that BufferedReader extends.
If you don't understand my response, don't ignore it, ask a question.
- 06-21-2012, 08:06 PM #10
Member
- Join Date
- Jun 2012
- Posts
- 6
- Rep Power
- 0
Re: BufferedReader.readLine() slow reading long line.
It works, but not as I expected. BufferedReader::read() stops way before 2048. According to the docs it stops for only these reasons,
1) condition not satisfiedThe specified number of characters have been read,
The read method of the underlying stream returns -1, indicating end-of-file, or
The ready method of the underlying stream returns false, indicating that further input requests would block.
2) condition not satisfied
3) doubtful with my 127 byte test message
Alas, I think I can work with it, thanks!
Similar Threads
-
AppDos Vulnerability while Using BufferedReader.readLine()
By Thiru in forum New To JavaReplies: 1Last Post: 02-27-2012, 01:37 PM -
Manifest file: line too long error
By nn12 in forum New To JavaReplies: 10Last Post: 02-01-2011, 03:01 PM -
readline() doesnt read whole line, are there another terminating characters ?
By fexadyn in forum NetworkingReplies: 1Last Post: 10-08-2009, 04:45 PM -
Reading text from a URL using BufferedReader
By Java Tip in forum Java TipReplies: 0Last Post: 12-26-2007, 10:17 AM -
BufferedReader: readLine method problems
By bbq in forum Advanced JavaReplies: 2Last Post: 06-30-2007, 02:27 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks