Commit 05e41da5 authored by qq247321453's avatar qq247321453

contentLength

parent 226796ec
...@@ -102,17 +102,21 @@ public class DownloadUtil { ...@@ -102,17 +102,21 @@ public class DownloadUtil {
try { try {
is = response.body().byteStream(); is = response.body().byteStream();
long total = response.body().contentLength(); long total = response.body().contentLength();
out = new FileOutputStream(file); if(contentLength > 0 && total != contentLength){
long sum = 0; listener.onDownloadFailed(new Exception("file length[" + total + "] < " + contentLen));
while ((len = is.read(buf)) != -1) { } else {
out.write(buf, 0, len); out = new FileOutputStream(file);
sum += len; long sum = 0;
int progress = (int) (sum * 1.0f / total * 100); while ((len = is.read(buf)) != -1) {
//下载中更新进度条 out.write(buf, 0, len);
listener.onDownloading(progress); sum += len;
int progress = (int) (sum * 1.0f / total * 100);
//下载中更新进度条
listener.onDownloading(progress);
}
out.flush();
saved = true;
} }
out.flush();
saved = true;
} catch (Exception ex) { } catch (Exception ex) {
listener.onDownloadFailed(ex); listener.onDownloadFailed(ex);
} finally { } finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment