summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/ftp/UploadTask.java
diff options
context:
space:
mode:
authorMichael Wilson2014-10-30 09:40:35 +0100
committerMichael Wilson2014-10-30 09:40:35 +0100
commit114d588f5ced55833400f8548f9b1208968aa3e4 (patch)
tree49eb2a189099b4d7c69655e63c865fc7b71baf54 /dozentenmodul/src/main/java/ftp/UploadTask.java
parentf (diff)
parent[client] remove misleading comment (diff)
downloadtutor-module-114d588f5ced55833400f8548f9b1208968aa3e4.tar.gz
tutor-module-114d588f5ced55833400f8548f9b1208968aa3e4.tar.xz
tutor-module-114d588f5ced55833400f8548f9b1208968aa3e4.zip
Merge branch 'master' of ssh://git.openslx.org/openslx-ng/tutor-module
Diffstat (limited to 'dozentenmodul/src/main/java/ftp/UploadTask.java')
-rw-r--r--dozentenmodul/src/main/java/ftp/UploadTask.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/dozentenmodul/src/main/java/ftp/UploadTask.java b/dozentenmodul/src/main/java/ftp/UploadTask.java
index 68af1f3c..2579b125 100644
--- a/dozentenmodul/src/main/java/ftp/UploadTask.java
+++ b/dozentenmodul/src/main/java/ftp/UploadTask.java
@@ -24,9 +24,7 @@ public class UploadTask extends SwingWorker<Void, Void> {
*/
private final static Logger LOGGER = Logger.getLogger(UploadTask.class);
- // 8MB buffer
private static final int BUFFER_SIZE = 1024 * 1024;
-
private static final double UPDATE_INTERVAL_SECONDS = 0.6;
private static final double UPDATE_INTERVAL_MS = UPDATE_INTERVAL_SECONDS * 1000;
private static final double BYTES_PER_MIB = 1024 * 1024;
@@ -60,11 +58,15 @@ public class UploadTask extends SwingWorker<Void, Void> {
util.connect();
util.uploadFile(uploadFile, destDir);
- FileInputStream inputStream = new FileInputStream(uploadFile);
+ // show filesize in the GUI
long fileSize = uploadFile.length();
Image.image.setFilesize(fileSize);
firePropertyChange("filesize", 0, fileSize);
+ // prepare input stream
+ FileInputStream inputStream = new FileInputStream(uploadFile);
+
+ // initialize the counters needed for speed calculations
percentCompleted = 0;
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = -1;
@@ -88,11 +90,12 @@ public class UploadTask extends SwingWorker<Void, Void> {
currentBytes = 0;
}
}
+ // finalize the upload by updating the progress bar one last time
+ // (in case we didn't get to do it because of the time interval)
percentCompleted = (int) ((totalBytesRead * 100) / fileSize);
setProgress(percentCompleted);
firePropertyChange("bytesread", 0, totalBytesRead);
inputStream.close();
-
util.finish();
} catch (FTPException ex) {
JOptionPane.showMessageDialog(null,