added support for displaying the current download speed

This commit is contained in:
kappa1 2008-05-22 00:04:11 +00:00
parent fab73d2e8f
commit 164b6f9008
1 changed files with 22 additions and 0 deletions

View File

@ -744,12 +744,34 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
int bufferSize;
long downloadStartTime = System.currentTimeMillis();
int downloadedAmount = 0;
String downloadSpeedMessage = "";
while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1) {
debug_sleep(10);
fos.write(buffer, 0, bufferSize);
currentSizeDownload += bufferSize;
percentage = initialPercentage + ((currentSizeDownload * 45) / totalSizeDownload);
subtaskMessage = "Retrieving: " + currentFile + " " + ((currentSizeDownload * 100) / totalSizeDownload) + "%";
downloadedAmount += bufferSize;
long timeLapse = System.currentTimeMillis() - downloadStartTime;
// update only if a second or more has passed
if (timeLapse >= 1000) {
// get kb/s, nice that bytes/millis is same as kilobytes/seconds
float downloadSpeed = (float) bufferSize / timeLapse;
// round to two decimal places
downloadSpeed = ((int)(downloadSpeed*100))/100f;
// set current speed message
downloadSpeedMessage = " @ " + downloadSpeed + " KB/sec";
// reset downloaded amount
downloadedAmount = 0;
// reset start time
downloadStartTime = System.currentTimeMillis();
}
subtaskMessage += downloadSpeedMessage;
}
inputstream.close();