Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2003
Added on Sep 24 2003
4 comments
325 views