Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -179,10 +189,13 @@ public boolean handleMessage(Message msg) {
private void dispose(final ArrayList<IFileDownloadMessenger> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -116,18 +117,32 @@ private void addUserRequiredHeader(FileDownloadConnection connection) {
String name;
List<String> list;

Stack<String> names = new Stack<>();
Stack<List<String>> lists = new Stack<>();

// add addition headers which is provided by the user
Set<Map.Entry<String, List<String>>> entries = additionHeaders.entrySet();
for (Map.Entry<String, List<String>> 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);
}
}
}

}
}
}
Expand Down