BufferedReader ready() unreliable with HttpsURLConnection
843811Sep 24 2003 — edited Sep 26 2003 RedHat 9, j2sdk1.4.2_01, jboss tomcat.
Hi all,
I have an experience to share. I just found that the "ready" function is reliable if it comes from HttpURLConnection.getInputStream. However, when it comes from HttpsURLConnection.getInputStream, it returns false even though there is data in the input stream. Only after a first read call and there is still data, the ready returns true. Anyone has an idea what's wrong ?
Some codes to proof this:
******** a portion taken out *********
//////////////
// All url connection opening and setproperty done upfront
//////////////
BufferedReader in = new BufferedReader(new InputStreamReader(MyHttpsURLConnection.getInputStream()));
int iTimeout = 0;
boolean bCheck = false;
boolean bReadSomething = false;
String inputline = null;
while (iTimeout < 60){
bCheck = in.ready();
System.out.println("in.ready() : " + bCheck);
if (bCheck){
inputline = in.readLine();
if (null == inputline)
break;
bReadSomething = true;
System.out.println(inputline);
}
else {
Thread.sleep(1000);
iTimeout++;
}
}
if (!bReadSomething) {
inputline = in.readLine();
while (inputline != null) {
System.out.println(inputline);
System.out.println("in.ready() : " + bCheck);
inputline = in.readLine();
}
}
******** a portion taken out *********
I made sure my servlet sends more than one line of data and did a flush after println. Anyone have the same experience ?
ltkhoo