Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

BufferedReader ready() method with httpsconnection

  Asked By: Jada    Date: Apr 22    Category: Java    Views: 1110
  

I just joined as I am just starting to work in Java. I have a
problem using httpsconnection with a bufferedreader and checking the
ready(). When the network is slow, my bufferedreader will not be
ready() and I will sleep for a few seconds before checking again.
But, once the ready() has gone to false, it never comes back and
becomes true no matter how long I sleep or who many times I check
back.

Has anyone had this experience?. Here is the code I am running to
read the line from the bufferedreader. It will get part way through
and then ready() becomes false and never goes back to true.

//----------------------------------------
// Read a timed buffer
public String readBufferLine()
{
String line = null;
boolean done = false;
boolean slept = false;
boolean brtest = false;
boolean bufferready = false;
int trycounter = 0;
// while trying to read the line loop
while (!done)
{
// if the maximum number of tries have occurred, exit the
loop
if (trycounter > timeout)
{
System.out.println("Time exceeded...");
line = defaultstr;
done = true;
}
// if maximum number of tries have not occured, try to
read the line
else
{
// increment the try counter
trycounter = trycounter + 1;
// check to see if the buffer is ready
try
{
brtest = br.ready();
}
catch (IOException ioe)
{
// error occurred when check if the buffer is
ready
System.out.println("Error occurred while testing
buffer...");
line = defaultstr;
done = true;
}
// if buffer is not ready and no error has yet
occurred, sleep for a bit
if (!done && !brtest)
{
try
{
// sleep
slept = true;
Thread.sleep(timesleep);
System.out.print("*");
}
catch (Exception e)
{
// error occurred while sleeping
System.out.println("Error occurred while
sleeping...");
line = defaultstr;
done = true;
}
}
// no error has occurrec and buffer is ready to be
read
else if (!done)
{
try
{
// read the line from the buffer
line = br.readLine();
}
catch (IOException ioe)
{
// an error occurred ready the buffer
System.out.println("Error occurred while
testing buffer...");
line = defaultstr;
done = true;
}
// Check if it is the end of the reader (last line
is "")
if (line == null)
{
System.out.println("End of file...");
}
done = true;
}
}
}
// a delay happend at some point
if(slept)
{
System.out.println("!");
}
return line;
}// end method readBufferLine
//--------------------------------------------------

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Davi Costa     Answered On: Apr 22

Does anyone know of a Java list where this question would apply? I
am really stuck and need some help. None of my books are any help
and I have searched the web with no success.

 
Didn't find what you were looking for? Find more on BufferedReader ready() method with httpsconnection Or get search suggestion and latest updates.