Skip to content

Commit 0bf429e

Browse files
committed
fix(Downloader.java): fix breakpoint resumes progress calculation error
1 parent 5c5e801 commit 0bf429e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

agentweb-download/src/main/java/com/just/agentweb/download/Downloader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ private int doDownload() throws IOException {
230230

231231
final boolean isEncodingChunked = "chunked".equalsIgnoreCase(
232232
mHttpURLConnection.getHeaderField("Transfer-Encoding"));
233-
final boolean hasLength = ((this.mTotals = getHeaderFieldLong(mHttpURLConnection, "Content-Length")) == -1);
234-
LogUtils.i(TAG, "content-length:" + this.mTotals);
233+
long tmpLength = -1;
234+
final boolean hasLength = ((tmpLength = getHeaderFieldLong(mHttpURLConnection, "Content-Length")) == -1);
235+
LogUtils.i(TAG, "content-length:" + this.mTotals + " code:" + mHttpURLConnection.getResponseCode() + " tmpLength:" + tmpLength);
235236
// 获取不到文件长度
236237
final boolean finishKnown = isEncodingChunked || hasLength;
237238
if (finishKnown) {
@@ -250,6 +251,9 @@ private int doDownload() throws IOException {
250251
new LoadingRandomAccessFile(mDownloadTask.getFile()),
251252
false);
252253
case HTTP_PARTIAL:
254+
if (tmpLength + mDownloadTask.getFile().length() != this.mTotals) {
255+
return ERROR_LOAD;
256+
}
253257
return transferData(mHttpURLConnection.getInputStream(),
254258
new LoadingRandomAccessFile(mDownloadTask.getFile()),
255259
true);

sample/src/main/java/com/just/agentweb/sample/fragment/AgentWebFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public boolean onStart(String url, String userAgent, String contentDisposition,
185185
.setEnableIndicator(true) // false 关闭进度通知
186186
.addHeader("Cookie", "xx") // 自定义请求头
187187
.setAutoOpen(true) // 下载完成自动打开
188-
.setForceDownload(false); // 强制下载,不管网络网络类型
188+
.setForceDownload(true); // 强制下载,不管网络网络类型
189189
return false;
190190
}
191191

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

0 commit comments

Comments
 (0)