diff options
| author | tspitzer | 2013-09-30 09:17:29 +0200 |
|---|---|---|
| committer | tspitzer | 2013-09-30 09:17:29 +0200 |
| commit | 1d1153c6262f0ec69a7f29c92ba2c389f37e7c83 (patch) | |
| tree | 1d0a745266b8769db1e70ee17caa0c338c3effbc /Dozentenmodul/src/downloader/DownloadTask.java | |
| parent | Erste Version fast fertig (diff) | |
| download | tutor-module-1d1153c6262f0ec69a7f29c92ba2c389f37e7c83.tar.gz tutor-module-1d1153c6262f0ec69a7f29c92ba2c389f37e7c83.tar.xz tutor-module-1d1153c6262f0ec69a7f29c92ba2c389f37e7c83.zip | |
actual
Diffstat (limited to 'Dozentenmodul/src/downloader/DownloadTask.java')
| -rw-r--r-- | Dozentenmodul/src/downloader/DownloadTask.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Dozentenmodul/src/downloader/DownloadTask.java b/Dozentenmodul/src/downloader/DownloadTask.java index cf04f387..bec366bc 100644 --- a/Dozentenmodul/src/downloader/DownloadTask.java +++ b/Dozentenmodul/src/downloader/DownloadTask.java @@ -54,7 +54,9 @@ public class DownloadTask extends SwingWorker<Void, Void> { int bytesRead = -1;
long totalBytesRead = 0;
int percentCompleted = 0;
-
+ long start=System.nanoTime();
+ final double NANOS_PER_SECOND = 1000000000.0;
+ final double BYTES_PER_MIB = 1024*1024;
long fileSize = util.getFileSize(downloadPath);
//gui.setFileSize(fileSize);
@@ -70,8 +72,10 @@ public class DownloadTask extends SwingWorker<Void, Void> { outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
//System.out.println(totalBytesRead);
+ double speed = NANOS_PER_SECOND / BYTES_PER_MIB * totalBytesRead / (System.nanoTime() - start + 1);
percentCompleted = (int) (totalBytesRead * 100 / fileSize);
setProgress(percentCompleted);
+ firePropertyChange("speed", 0, speed);
}
|
