Commit 05e41da5 authored by qq247321453's avatar qq247321453

contentLength

parent 226796ec
...@@ -102,6 +102,9 @@ public class DownloadUtil { ...@@ -102,6 +102,9 @@ public class DownloadUtil {
try { try {
is = response.body().byteStream(); is = response.body().byteStream();
long total = response.body().contentLength(); long total = response.body().contentLength();
if(contentLength > 0 && total != contentLength){
listener.onDownloadFailed(new Exception("file length[" + total + "] < " + contentLen));
} else {
out = new FileOutputStream(file); out = new FileOutputStream(file);
long sum = 0; long sum = 0;
while ((len = is.read(buf)) != -1) { while ((len = is.read(buf)) != -1) {
...@@ -113,6 +116,7 @@ public class DownloadUtil { ...@@ -113,6 +116,7 @@ public class DownloadUtil {
} }
out.flush(); out.flush();
saved = true; 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