added support for displaying the current download speed
This commit is contained in:
parent
fab73d2e8f
commit
164b6f9008
|
@ -744,12 +744,34 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
||||||
|
|
||||||
|
|
||||||
int bufferSize;
|
int bufferSize;
|
||||||
|
long downloadStartTime = System.currentTimeMillis();
|
||||||
|
int downloadedAmount = 0;
|
||||||
|
String downloadSpeedMessage = "";
|
||||||
|
|
||||||
while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1) {
|
while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1) {
|
||||||
debug_sleep(10);
|
debug_sleep(10);
|
||||||
fos.write(buffer, 0, bufferSize);
|
fos.write(buffer, 0, bufferSize);
|
||||||
currentSizeDownload += bufferSize;
|
currentSizeDownload += bufferSize;
|
||||||
percentage = initialPercentage + ((currentSizeDownload * 45) / totalSizeDownload);
|
percentage = initialPercentage + ((currentSizeDownload * 45) / totalSizeDownload);
|
||||||
subtaskMessage = "Retrieving: " + currentFile + " " + ((currentSizeDownload * 100) / 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();
|
inputstream.close();
|
||||||
|
|
Loading…
Reference in New Issue