blocking io

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);
}
 
P

Pete Barrett

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?
Isn't this what a cache is all about? That the file is in the cache,
therefore immediately available, therefore no progress to report?

Pete Barrett
 
B

bitshit

Pete Barrett said:
Isn't this what a cache is all about? That the file is in the cache,
therefore immediately available, therefore no progress to report?

Pete Barrett

true.

but the problem is when downloading the file from a url (the first time, not
from cache). It just doesn't read any progress, just as if the jvm downloads
..class files in some seperate thread i can't access till its done. it just
returns the filesize after some time (the time nescesary to download it)
 
B

bitshit

Pete Barrett said:
Isn't this what a cache is all about? That the file is in the cache,
therefore immediately available, therefore no progress to report?

Pete Barrett

true.

but the problem is when downloading the file from a url (the first time, not
from cache). It just doesn't read any progress, just as if the jvm downloads
..class files in some seperate thread i can't access till its done. it just
returns the filesize after some time (the time nescesary to download it)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top