From 9648fec24e4834b366c8680da1451c2edf58eec5 Mon Sep 17 00:00:00 2001 From: MohsenDehghankar Date: Wed, 17 Jun 2020 16:50:39 +0430 Subject: [PATCH 1/3] 1335 fixed --- .../filedownloader/download/ConnectTask.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java b/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java index 4c528bfc..79d926bf 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java +++ b/library/src/main/java/com/liulishuo/filedownloader/download/ConnectTask.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Stack; /** * The connect task which used for connect to the backend. @@ -116,18 +117,32 @@ private void addUserRequiredHeader(FileDownloadConnection connection) { String name; List list; + Stack names = new Stack<>(); + Stack> lists = new Stack<>(); + // add addition headers which is provided by the user Set>> entries = additionHeaders.entrySet(); for (Map.Entry> e : entries) { name = e.getKey(); list = e.getValue(); + names.push(name); + lists.push(list); + /*if (list != null) { + for (String value : list) { + connection.addHeader(name, value); + } + }*/ + } + + while (lists.size() > 0) { + list = lists.pop(); + name = names.pop(); if (list != null) { for (String value : list) { connection.addHeader(name, value); } } } - } } } From 623f83a7fba2eb4bf3b95f9b351824e076d8bd7c Mon Sep 17 00:00:00 2001 From: MohsenDehghankar Date: Wed, 17 Jun 2020 17:29:37 +0430 Subject: [PATCH 2/3] checking if mTask is null before calling interceptBlockCompleteMessage() --- .../filedownloader/FileDownloadMessageStation.java | 12 +++++++++++- .../filedownloader/FileDownloadMessenger.java | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java b/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java index 09c9f8ca..29e6eca8 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java +++ b/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java @@ -22,6 +22,7 @@ import com.liulishuo.filedownloader.util.FileDownloadExecutors; +import java.io.File; import java.util.ArrayList; import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; @@ -63,10 +64,19 @@ void requestEnqueue(final IFileDownloadMessenger messenger, return; } - if (interceptBlockCompleteMessage(messenger)) { + // check if messenger.mTask is null + // if null, return; according to filedownloader/FileDownloadMessenger.java -> process() + // line 200 to 210 + if (messenger instanceof FileDownloadMessenger + && ((FileDownloadMessenger) messenger).hasTask()) { + if (interceptBlockCompleteMessage(messenger)) { + return; + } + } else { return; } + if (!isIntervalValid()) { // invalid // clear all waiting queue. diff --git a/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessenger.java b/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessenger.java index 80fce2f0..2cbf73a4 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessenger.java +++ b/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessenger.java @@ -400,4 +400,8 @@ public String toString() { return FileDownloadUtils.formatString("%d:%s", mTask == null ? -1 : mTask.getOrigin().getId(), super.toString()); } + + public boolean hasTask() { + return mTask != null; + } } From 62fe96b7aeff7c7955c992b837448deb9d7355cc Mon Sep 17 00:00:00 2001 From: MohsenDehghankar Date: Wed, 17 Jun 2020 17:38:16 +0430 Subject: [PATCH 3/3] checking if mTask is null in dispose() --- .../filedownloader/FileDownloadMessageStation.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java b/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java index 29e6eca8..62016e38 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java +++ b/library/src/main/java/com/liulishuo/filedownloader/FileDownloadMessageStation.java @@ -189,10 +189,13 @@ public boolean handleMessage(Message msg) { private void dispose(final ArrayList disposingList) { // dispose Sub-package-size each time. for (IFileDownloadMessenger iFileDownloadMessenger : disposingList) { - if (interceptBlockCompleteMessage(iFileDownloadMessenger)) { - continue; + if (iFileDownloadMessenger instanceof FileDownloadMessenger && + ((FileDownloadMessenger) iFileDownloadMessenger).hasTask()) { + if (interceptBlockCompleteMessage(iFileDownloadMessenger)) { + continue; + } + iFileDownloadMessenger.handoverMessage(); } - iFileDownloadMessenger.handoverMessage(); } disposingList.clear();