Skip to content

Commit

Permalink
fix(Downloader.java): fix breakpoint resumes progress calculation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Justson committed Mar 6, 2018
1 parent 5c5e801 commit 0bf429e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ private int doDownload() throws IOException {

final boolean isEncodingChunked = "chunked".equalsIgnoreCase(
mHttpURLConnection.getHeaderField("Transfer-Encoding"));
final boolean hasLength = ((this.mTotals = getHeaderFieldLong(mHttpURLConnection, "Content-Length")) == -1);
LogUtils.i(TAG, "content-length:" + this.mTotals);
long tmpLength = -1;
final boolean hasLength = ((tmpLength = getHeaderFieldLong(mHttpURLConnection, "Content-Length")) == -1);
LogUtils.i(TAG, "content-length:" + this.mTotals + " code:" + mHttpURLConnection.getResponseCode() + " tmpLength:" + tmpLength);
// 获取不到文件长度
final boolean finishKnown = isEncodingChunked || hasLength;
if (finishKnown) {
Expand All @@ -250,6 +251,9 @@ private int doDownload() throws IOException {
new LoadingRandomAccessFile(mDownloadTask.getFile()),
false);
case HTTP_PARTIAL:
if (tmpLength + mDownloadTask.getFile().length() != this.mTotals) {
return ERROR_LOAD;
}
return transferData(mHttpURLConnection.getInputStream(),
new LoadingRandomAccessFile(mDownloadTask.getFile()),
true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public boolean onStart(String url, String userAgent, String contentDisposition,
.setEnableIndicator(true) // false 关闭进度通知
.addHeader("Cookie", "xx") // 自定义请求头
.setAutoOpen(true) // 下载完成自动打开
.setForceDownload(false); // 强制下载,不管网络网络类型
.setForceDownload(true); // 强制下载,不管网络网络类型
return false;
}

Expand Down Expand Up @@ -517,7 +517,7 @@ public boolean onMenuItemClick(MenuItem item) {
case R.id.error_website:
loadErrorWebSite();
// test DownloadingService
/*LogUtils.i(TAG, " :" + mDownloadingService + " " + (mDownloadingService == null ? "" : mDownloadingService.isShutdown()) + " :" + mExtraService);
/*LogUtils.i(TAG, " :" + mDownloadingService + " " + (mDownloadingService == null ? "" : mDownloadingService.isShutdown()) + " :" + mExtraService);
if (mDownloadingService != null && !mDownloadingService.isShutdown()) {
mExtraService = mDownloadingService.shutdownNow();
LogUtils.i(TAG, "mExtraService::" + mExtraService);
Expand Down

0 comments on commit 0bf429e

Please sign in to comment.