Fixed download size for File and FTP download
This commit is contained in:
parent
79e336c1cc
commit
1c985b8c2d
1 changed files with 4 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ public class UeBehaviourFileDownload extends UeBehaviour {
|
||||||
@Configurable("File address")
|
@Configurable("File address")
|
||||||
private String url = "http://speedtest.ftp.otenet.gr/files/test1Mb.db";
|
private String url = "http://speedtest.ftp.otenet.gr/files/test1Mb.db";
|
||||||
|
|
||||||
|
private transient long estimatedDataLength = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute() throws IOException {
|
protected void execute() throws IOException {
|
||||||
|
|
@ -34,15 +35,16 @@ public class UeBehaviourFileDownload extends UeBehaviour {
|
||||||
connection.connect();
|
connection.connect();
|
||||||
InputStream in = connection.getInputStream();
|
InputStream in = connection.getInputStream();
|
||||||
|
|
||||||
long total = in.available();
|
|
||||||
long progress = 0;
|
long progress = 0;
|
||||||
long read = 0;
|
long read = 0;
|
||||||
|
|
||||||
while((read = in.read(data)) != -1 && !stopExecution()){
|
while((read = in.read(data)) != -1 && !stopExecution()){
|
||||||
progress += read;
|
progress += read;
|
||||||
super.setProgress((float)progress/total);
|
super.setProgress((float)progress/estimatedDataLength);
|
||||||
super.setHandledIncomingData(read);
|
super.setHandledIncomingData(read);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
estimatedDataLength = progress;
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue