|
From: <ka...@us...> - 2008-05-22 00:04:13
|
Revision: 3069
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3069&view=rev
Author: kappa1
Date: 2008-05-21 17:04:11 -0700 (Wed, 21 May 2008)
Log Message:
-----------
added support for displaying the current download speed
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2008-05-11 14:41:46 UTC (rev 3068)
+++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2008-05-22 00:04:11 UTC (rev 3069)
@@ -744,12 +744,34 @@
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();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|