throw new InvalidHttpResponseException(url, response);
}
final HttpEntity responseEntity = response.getEntity();
final long expectedSize = responseEntity.getContentLength();
publish(new Task() {
@Override
public void execute() throws Exception {
_downloadProgressWindow.setExpectedSize(file, expectedSize);
}
});
inputStream = responseEntity.getContent();
outputStream = new BufferedOutputStream(new FileOutputStream(file));
long bytes = 0;
for (int numBytes = inputStream.read(buffer); numBytes != -1; numBytes = inputStream.read(buffer)) {
if (_cancelled) {
break;
}
outputStream.write(buffer, 0, numBytes);
bytes += numBytes;
final long totalBytes = bytes;
publish(new Task() {
@Override
public void execute() throws Exception {
_downloadProgressWindow.setProgress(file, totalBytes);
}
});
}
if (!_cancelled) {
publish(new Task() {
@Override
public void execute() throws Exception {
_downloadProgressWindow.setFinished(file);
}
});