Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help with BufferReader.read()

 
V Johnson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Cheers
Lupo
 
Nick Revak
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic