From 37306c4ac39416662d8501949d263d0c45f0d062 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 29 Oct 2014 17:48:09 +0100 Subject: [client] some comments for UploadTask --- dozentenmodul/src/main/java/ftp/UploadTask.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'dozentenmodul/src/main/java/ftp/UploadTask.java') diff --git a/dozentenmodul/src/main/java/ftp/UploadTask.java b/dozentenmodul/src/main/java/ftp/UploadTask.java index 68af1f3c..e0c6db29 100644 --- a/dozentenmodul/src/main/java/ftp/UploadTask.java +++ b/dozentenmodul/src/main/java/ftp/UploadTask.java @@ -60,11 +60,15 @@ public class UploadTask extends SwingWorker { 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 +92,12 @@ public class UploadTask extends SwingWorker { 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, -- cgit v1.2.3-55-g7522