Skip to content
Merged
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 @@ -88,19 +88,7 @@ public ProgressiveDownloader(
public void download(@Nullable ProgressListener progressListener)
throws IOException, InterruptedException {
this.progressListener = progressListener;
downloadRunnable =
new RunnableFutureTask<Void, IOException>() {
@Override
protected Void doWork() throws IOException {
cacheWriter.cache();
return null;
}

@Override
protected void cancelWork() {
cacheWriter.cancel();
}
};
downloadRunnable = createDownloadTask();

if (priorityTaskManager != null) {
priorityTaskManager.add(C.PRIORITY_DOWNLOAD);
Expand All @@ -119,6 +107,8 @@ protected void cancelWork() {
Throwable cause = Assertions.checkNotNull(e.getCause());
if (cause instanceof PriorityTooLowException) {
// The next loop iteration will block until the task is able to proceed.
// recreate downloadRunnable in order to prevent error state caching
downloadRunnable = createDownloadTask();
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
Expand Down Expand Up @@ -161,4 +151,19 @@ private void onProgress(long contentLength, long bytesCached, long newBytesCache
: ((bytesCached * 100f) / contentLength);
progressListener.onProgress(contentLength, bytesCached, percentDownloaded);
}

private RunnableFutureTask<Void, IOException> createDownloadTask() {
return new RunnableFutureTask<Void, IOException>() {
@Override
protected Void doWork() throws IOException {
cacheWriter.cache();
return null;
}

@Override
protected void cancelWork() {
cacheWriter.cancel();
}
};
}
}