URLConnection: kaffe bug
Dandekar, Hrishikesh
Hrishikesh_Dandekar at NAI.com
Mon May 17 12:04:01 PDT 1999
i guess connection.connect() doesnt need be called explicitly as the other
methods from URLConnection seem to internally invoke that method.
I also tried the explicit invocation but that doesnt help either.
I'm attaching the piece of code which works as expected on sun jvm, but
fails under kaffe.... Interestingly only SOME of the URLConnection.get*(_);
methods fail on kaffe.
I have prefixed those lines with "^^^^^^". My immediate concern is that
the URLConnection.getContentLength() fails .
To handle that i've introduced a bug fix (Kaffepatch) into the code...
please let me know if there can be a better way to handle that.
Thx!
-Rishi
Code Snap follows:
try {
URL url = new URL( urlclassName);
URLConnection connection = url.openConnection();
// connection.connect();
System.out.println("Loading from URL: " + connection.getURL()
);
^^^^ System.out.println("\nContent type is: " +
connection.getContentType());
^^^^ System.out.println("\nContent Encoding is: " +
connection.getContentEncoding());
^^^^ int length = connection.getContentLength();
InputStream inputStream = connection.getInputStream();
System.out.println("InputStream length = " + length); // Failure
if -1
boolean Kaffepatch= false;
if( length == -1)
{
System.out.println("\n
URLConnection.getContentLength failed!!!... using the patch\n");
Kaffepatch= true;
length = SOME_BIG_VALUE; // Hardcoded buffer
value as content length cannot be determined
}
byte[] data = new byte[length];
int bytesread = inputStream.read(data); // Actual byte
transfer
System.out.println(" Content Length is = " + bytesread);
if(Kaffepatch)
{
byte[] newdata= new byte[bytesread];
System.arraycopy(data,0,newdata ,0, bytesread);
data= newdata;
}
inputStream.close();
return data;
}
catch(Exception ex) {
print(" Class not found!! - Exception:");
ex.printStackTrace();
return null;
}
> -----Original Message-----
> From: Aaron M. Renn [SMTP:arenn at urbanophile.com]
> Sent: Friday, May 14, 1999 5:41 PM
> To: kaffe at rufus.w3.org
> Cc: Yee, Richard; Schwab, Steve
> Subject: Re: URLConnection
>
> Dandekar, Hrishikesh (Hrishikesh_Dandekar at NAI.com) wrote:
> > URl url= new URL(urlname);
> > URLConnection connection = url.openConnection();
> > ********* int length= connection.getContentLength(); **********
> > .....
> >
> > However, the methods connection. { getContentLength() ,
> getContentEncoding()
> > , getcontentType() } fail by returning -1 or null...
> > The same code works fine with sun's jvm...
> >
> > what could be the possible problem?
>
> Try calling connection.connect() first.
>
> --
> Aaron M. Renn (arenn at urbanophile.com) http://www.urbanophile.com/arenn/
More information about the kaffe
mailing list