B
bitshit
Hi,
I made a simple progressbar to show in my applet when I download data. I
download this data over an URLConnection with the option setUseCache(true).
I know that it can't cache any file other than .class files, so i've renamed
my zip data file to .class, so the jvm caches it. This all works fine,
except that I can't read progress from the input stream when I download
..class files with setUseCache enabled. When downloading class files with
setUseCache(false) or other files than .class it works ok. Does anyone know
what's causing this?
The source looks something like this:
URL url = new URL(filename);
URLConnection c = url.openConnection();
c.setUseCaches(true);
int size=0;
try{ size = c.getContentLength(); }
catch(Exception e) {}
if(size<=0) size=4*1024*1024;
InputStream i = c.getInputStream();
byteData = new byte[size];
int realLength=0, bytesRead;
int length=bis.available();
if (length <= 0) length = 5120;
byte[] tmpBuff=new byte[length];
//read in bytes from the stream & update the progresslistener if
available
while((bytesRead = bis.read(tmpBuff,0,length)) != -1)
{
System.arraycopy(tmpBuff, 0, byteData, realLength, bytesRead);
realLength+=bytesRead;
if(plistener!=null) plistener.update(bytesRead);
}
I made a simple progressbar to show in my applet when I download data. I
download this data over an URLConnection with the option setUseCache(true).
I know that it can't cache any file other than .class files, so i've renamed
my zip data file to .class, so the jvm caches it. This all works fine,
except that I can't read progress from the input stream when I download
..class files with setUseCache enabled. When downloading class files with
setUseCache(false) or other files than .class it works ok. Does anyone know
what's causing this?
The source looks something like this:
URL url = new URL(filename);
URLConnection c = url.openConnection();
c.setUseCaches(true);
int size=0;
try{ size = c.getContentLength(); }
catch(Exception e) {}
if(size<=0) size=4*1024*1024;
InputStream i = c.getInputStream();
byteData = new byte[size];
int realLength=0, bytesRead;
int length=bis.available();
if (length <= 0) length = 5120;
byte[] tmpBuff=new byte[length];
//read in bytes from the stream & update the progresslistener if
available
while((bytesRead = bis.read(tmpBuff,0,length)) != -1)
{
System.arraycopy(tmpBuff, 0, byteData, realLength, bytesRead);
realLength+=bytesRead;
if(plistener!=null) plistener.update(bytesRead);
}