I am trying to make a gui, whereby users are able to download files. Currently I am able to call the wget command through a process, but I am struggling to use it along with swingworker.
How would I go about tracking the progress of the downloading and updating a gui simultaneously?
Currently I have tried using this method:
ShellProcess.command("wget --progress=dot "+_url);
Where command is the method that creates the process:
InputStream stdout = _process.getInputStream();
BufferedReader stdoutBuffered =new BufferedReader(new InputStreamReader(stdout));
String line = null;
String output ="";
try {
while ((line = _stdoutBuffered.readLine()) != null ) {
// System.out.println(line);
output+=(line+" ");
System.out.println(line +" SHELL");
_progress++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
_progress = 0;
return output;
}
I am trying to count the amount of lines outputted as "wget --progress=dot" should output a line for every percent of progress. But this does not seem to work.
My doInBackground method inside the swingworker looks like this:
@Override
protected Integer doInBackground() throws Exception {
// Start
download .command("wget "+_url);
ShellProcess.command("wget --progress=dot "+_url);
int progress = 0;
while (progress<101){
progress = ShellProcess.getProgress() %100 ;
publish(ShellProcess.getOutput());
setProgress(progress);
}
return 1;
}
Any help would be appreciated.