Fixed download size for File and FTP download

This commit is contained in:
Ziver Koc 2014-08-13 13:44:44 +02:00
parent 79e336c1cc
commit 1c985b8c2d

View file

@ -22,6 +22,7 @@ public class UeBehaviourFileDownload extends UeBehaviour {
@Configurable("File address")
private String url = "http://speedtest.ftp.otenet.gr/files/test1Mb.db";
private transient long estimatedDataLength = -1;
@Override
protected void execute() throws IOException {
@ -34,15 +35,16 @@ public class UeBehaviourFileDownload extends UeBehaviour {
connection.connect();
InputStream in = connection.getInputStream();
long total = in.available();
long progress = 0;
long read = 0;
while((read = in.read(data)) != -1 && !stopExecution()){
progress += read;
super.setProgress((float)progress/total);
super.setProgress((float)progress/estimatedDataLength);
super.setHandledIncomingData(read);
}
estimatedDataLength = progress;
in.close();
}