• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Please help with BufferReader.read()

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic