 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
bitshit Guest
|
Posted: Fri Jul 15, 2005 10:57 pm Post subject: plugin cache |
|
|
I guess my question is a jvm specific question so here it goes:
When I download a file with a .class extension over an urlconnection, with
setUseCache(true), the jvm will automatically cache the .class file in the
jpi_cache.
This is ok as I want this .class file (which is actually a zip file) to be
cached. The .class extension is just a trick to make the jvm cache this data
file. But when I set the urlconnection to setUseCache(true) I won't be able
to print the progress I make reading bytes from the stream. With
setUseCache(false) it works, but then the file won't get cached obviously :(
Maybe there's some way to download from the urlconnection first without
caching (and thus be able to read the progress) and make the jvm cache it
afterwards by reusing the urlconnection or something?
Any ideas?
here's the code (im running this from an applet):
URL url = new URL(Test.url);
URLConnection c = url.openConnection();
c.setUseCaches(true);
int headerfield_contentlength = c.getContentLength();
InputStream f = c.getInputStream();
BufferedInputStream bis = new BufferedInputStream(f);
byte[] byteData = new byte[headerfield_contentlength];
int realLength=0, bytesRead;
int length=bis.available();
if(length>5120) length=5120;
byte[] tmpBuff=new byte[length];
System.out.println("Downloading...");
while((bytesRead = bis.read(tmpBuff,0,length)) != -1)
{
System.arraycopy(tmpBuff, 0, byteData, realLength, bytesRead);
realLength+=bytesRead;
System.out.println("read "+bytesRead+" bytes of data...");
}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|