Fixes "gzip finished without exhausting source" error

This commit is contained in:
Martin Fietz 2015-06-03 11:36:25 +02:00
parent bb3f7255a9
commit 6a83057e28
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"); Log.d(TAG, "Starting download");
while (!cancelled try {
&& (count = connection.read(buffer)) != -1) { while (!cancelled
out.write(buffer, 0, count); && (count = connection.read(buffer)) != -1) {
request.setSoFar(request.getSoFar() + count); out.write(buffer, 0, count);
request.setProgressPercent((int) (((double) request request.setSoFar(request.getSoFar() + count);
.getSoFar() / (double) request request.setProgressPercent((int) (((double) request
.getSize()) * 100)); .getSoFar() / (double) request
.getSize()) * 100));
}
} catch(IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
} }
if (cancelled) { if (cancelled) {
onCancelled(); onCancelled();
@ -210,6 +214,9 @@ public class HttpDownloader extends Downloader {
request.getSize() request.getSize()
); );
return; return;
} else if(request.getSoFar() == 0){
onFail(DownloadError.ERROR_IO_ERROR, "Download completed, but nothing was read");
return;
} }
onSuccess(); onSuccess();
} }