|
From: <ka...@us...> - 2012-04-22 22:51:54
|
Revision: 3764
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3764&view=rev
Author: kappa1
Date: 2012-04-22 22:51:47 +0000 (Sun, 22 Apr 2012)
Log Message:
-----------
AppletLoader: add try/finally block to ensure file is closed on exception in the downloadJars(), thx to MatthiasM for pointing it out.
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 2012-04-22 22:21:41 UTC (rev 3763)
+++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2012-04-22 22:51:47 UTC (rev 3764)
@@ -1464,44 +1464,47 @@
String currentFile = getFileName(urlList[i]);
InputStream inputstream = getJarInputStream(currentFile, urlconnection);
FileOutputStream fos = new FileOutputStream(path + currentFile);
-
-
+
+
int bufferSize;
long downloadStartTime = System.currentTimeMillis();
int downloadedAmount = 0;
int fileSize = 0;
String downloadSpeedMessage = "";
-
- while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1) {
- debug_sleep(10);
- fos.write(buffer, 0, bufferSize);
- currentSizeDownload += bufferSize;
- fileSize += 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) downloadedAmount / 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();
+
+ try {
+ while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1) {
+ debug_sleep(10);
+ fos.write(buffer, 0, bufferSize);
+ currentSizeDownload += bufferSize;
+ fileSize += 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) downloadedAmount / 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;
}
-
- subtaskMessage += downloadSpeedMessage;
+
+ } finally {
+ inputstream.close();
+ fos.close();
}
-
- inputstream.close();
- fos.close();
-
+
// download complete, verify if it was successful
if (urlconnection instanceof HttpURLConnection) {
if (fileSize == fileSizes[i]) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|