Merge pull request #857 from mfietz/issue/854-gzip-not-exhausted

Fixes "gzip finished without exhausting source" error
This commit is contained in:
Tom Hennen 2015-06-04 21:19:13 -04:00
commit 2d4705461c
1 changed files with 14 additions and 7 deletions

View File

@ -188,13 +188,17 @@ public class HttpDownloader extends Downloader {
}
Log.d(TAG, "Starting download");
while (!cancelled
&& (count = connection.read(buffer)) != -1) {
out.write(buffer, 0, count);
request.setSoFar(request.getSoFar() + count);
request.setProgressPercent((int) (((double) request
.getSoFar() / (double) request
.getSize()) * 100));
try {
while (!cancelled
&& (count = connection.read(buffer)) != -1) {
out.write(buffer, 0, count);
request.setSoFar(request.getSoFar() + count);
request.setProgressPercent((int) (((double) request
.getSoFar() / (double) request
.getSize()) * 100));
}
} catch(IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
if (cancelled) {
onCancelled();
@ -210,6 +214,9 @@ public class HttpDownloader extends Downloader {
request.getSize()
);
return;
} else if(request.getSize() > 0 && request.getSoFar() == 0){
onFail(DownloadError.ERROR_IO_ERROR, "Download completed, but nothing was read");
return;
}
onSuccess();
}