Skip to Main Content

Java SE (Java Platform, Standard Edition)

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!

progress bar with zipped file download to applet

843807Jul 20 2010 — edited Jul 20 2010
Hello

I have an applet which downloads a .zip file from the server side and saves it on the local disk.
I added a progress bar to the applet to let the user know how many bytes it is going to download.
On the client side, the stream is unzipped on the fly, like:

URLConnection conn = url.openConnection();
conn.setDoOutput(true);
InputStream in = conn.getInputStream();
ZipInputStream zin = new ZipInputStream(in);
tot = 0 ;
while ((entry = zin.getNextEntry()) != null) {
int count;
byte data[] = new byte[BUFFER];
FileOutputStream fos = new FileOutputStream(dir + System.getProperty("file.separator") + entry.getName());
while ((count = zin.read(data, 0, BUFFER)) != -1) {
fos.write(data, 0, count);
tot += count ;
progress.updateProgress(tot) ;
}
fos.close();
}

The problem is that the dowloaded file is zipped, so the content length, on which I base the progress bar maximum, is not the real total of resulting bytes. This scrambles the progress bar indicator to percentages up to 234% and over...

Is there a way to obtain a correct value for the total final bytes ?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2010
Added on Jul 20 2010
4 comments
365 views