jQuery in Action, 3rd edition
The moose likes Sockets and Internet Protocols and the fly likes Please help with BufferReader.read() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Please help with BufferReader.read()" Watch "Please help with BufferReader.read()" New topic

Please help with BufferReader.read()

V Johnson

Joined: Jul 28, 2003
Posts: 1
The problem is that my application is hanging on the br.read()line!! Please help me...

Code Tags added by M^2
[ July 28, 2003: Message edited by: Michael Morris ]
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
well, if your program is *hanging* with the buffered reader, then I guess the read() is blocking.
There seems to be nothing on the network i/p buffer and hence the read() blocks, waiting for something to arrive.
It would be great if you can post the client code too.
In the meantime, I will look around the problem with a client of my own.

"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
Nick Revak

Joined: Jun 08, 2003
Posts: 4
The third parameter in the read is the maximum characters to attempt to read.
You could simply try setting your array size to a value much bigger than your would ever expect for contentLength.
But I also think you'd want to do your reads within a while loop (checking for end of stream). If you do this, you need to manage the size of each read to ensure you don't exceed your array.
Try this ....
int currentArrayPos = 0;
int count = 0;
//then, change the max char parameter in your read ....
while ((count = br.read(buf, 0, contentLength - currentArrayPos) != -1 ) {; //***HERE'S THE PROBLEM!!
// and limit the size of each read
currentArrayPos = currentArrayPos + count
I agree. Here's the link: http://aspose.com/file-tools
subject: Please help with BufferReader.read()
It's not a secret anymore!