Don't show progress if content length is unavailable

This commit is contained in:
topjohnwu 2019-01-18 16:28:12 -05:00
parent 6ea42a35a9
commit ab63b0e970

View File

@ -19,7 +19,7 @@ public class ProgressInputStream extends FilterInputStream {
@Override @Override
public int read() throws IOException { public int read() throws IOException {
int b = super.read(); int b = super.read();
if (b >= 0) { if (totalBytes > 0 && b >= 0) {
bytesDownloaded++; bytesDownloaded++;
Networking.mainHandler.post(() -> progress.onProgress(bytesDownloaded, totalBytes)); Networking.mainHandler.post(() -> progress.onProgress(bytesDownloaded, totalBytes));
} }
@ -34,7 +34,7 @@ public class ProgressInputStream extends FilterInputStream {
@Override @Override
public int read(byte[] b, int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IOException {
int sz = super.read(b, off, len); int sz = super.read(b, off, len);
if (sz > 0) { if (totalBytes > 0 && sz > 0) {
bytesDownloaded += sz; bytesDownloaded += sz;
Networking.mainHandler.post(() -> progress.onProgress(bytesDownloaded, totalBytes)); Networking.mainHandler.post(() -> progress.onProgress(bytesDownloaded, totalBytes));
} }