Open daiqiquan opened 4 years ago
android10版本会遇到网络不稳定时,下载异常中断
@oneornone That's not true. I'm on a 100mb/s very stable WiFi and I get this on every download where setConnectionCount
is more than 1. It's a library issue, not an Android one.
the same problem happen on my device: pixel3 running Android 11 . thanks!
@daiqiquan I face the same problem, and debug it for days. Finnally I found the cause and send the pull request. Hope helps.
@Jacksgong, will this fix be pushed to maven any time soon?
@slowlow79464 It has been modified in your way, but this error will still be reported
Hi, there!
I use temp fix before author can't approve merge request #425
@slowlow79464 & @mradzinski Thanks for help =)
========================
1. Add Override fixed classes (I created same package name, its doesn't matter)
CustomProcessFileStrategy.class
package com.liulishuo.okdownload.core.file;
import androidx.annotation.NonNull;
import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.breakpoint.DownloadStore;
public class CustomProcessFileStrategy extends ProcessFileStrategy {
@Override
@NonNull
public MultiPointOutputStream createProcessStream(@NonNull DownloadTask task,
@NonNull BreakpointInfo info,
@NonNull DownloadStore store) {
return new CustomMultiPointOutputStream(task, info, store);
}
}
and CustomMultiPointOutputStream.class
package com.liulishuo.okdownload.core.file;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.core.Util;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.breakpoint.DownloadStore;
import java.io.IOException;
public class CustomMultiPointOutputStream extends MultiPointOutputStream {
private static final String TAG = "CustomMultiPointOutputStream";
private final DownloadTask task;
CustomMultiPointOutputStream(@NonNull final DownloadTask task,
@NonNull BreakpointInfo info,
@NonNull DownloadStore store,
@Nullable Runnable syncRunnable) {
super(task, info, store, syncRunnable);
this.task = task;
}
public CustomMultiPointOutputStream(@NonNull DownloadTask task,
@NonNull BreakpointInfo info,
@NonNull DownloadStore store) {
this(task, info, store, null);
}
@Override
synchronized void close(int blockIndex) throws IOException {
final DownloadOutputStream outputStream = outputStreamMap.get(blockIndex);
if (outputStream != null) {
outputStream.close();
synchronized (noSyncLengthMap) {
// make sure the length of noSyncLengthMap is equal to outputStreamMap
outputStreamMap.remove(blockIndex);
noSyncLengthMap.remove(blockIndex);
}
Util.d(TAG, "OutputStream close task[" + task.getId() + "] block[" + blockIndex + "]");
}
}
}
2. Add in you Application.onCreate() class:
OkDownload.setSingletonInstance(
new OkDownload.Builder(this)
.processFileStrategy(new CustomProcessFileStrategy())
.build()
);
Enjoy!
这个解决方案好像并不能完全解决 还是有概率出现问题
关闭多线程下载,,,
Hi, there!
I use temp fix before author can't approve merge request #425
@slowlow79464 & @mradzinski Thanks for help =)
========================
1. Add Override fixed classes (I created same package name, its doesn't matter)
CustomProcessFileStrategy.class
package com.liulishuo.okdownload.core.file; import androidx.annotation.NonNull; import com.liulishuo.okdownload.DownloadTask; import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo; import com.liulishuo.okdownload.core.breakpoint.DownloadStore; public class CustomProcessFileStrategy extends ProcessFileStrategy { @Override @NonNull public MultiPointOutputStream createProcessStream(@NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadStore store) { return new CustomMultiPointOutputStream(task, info, store); } }
and CustomMultiPointOutputStream.class
package com.liulishuo.okdownload.core.file; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.liulishuo.okdownload.DownloadTask; import com.liulishuo.okdownload.core.Util; import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo; import com.liulishuo.okdownload.core.breakpoint.DownloadStore; import java.io.IOException; public class CustomMultiPointOutputStream extends MultiPointOutputStream { private static final String TAG = "CustomMultiPointOutputStream"; private final DownloadTask task; CustomMultiPointOutputStream(@NonNull final DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadStore store, @Nullable Runnable syncRunnable) { super(task, info, store, syncRunnable); this.task = task; } public CustomMultiPointOutputStream(@NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadStore store) { this(task, info, store, null); } @Override synchronized void close(int blockIndex) throws IOException { final DownloadOutputStream outputStream = outputStreamMap.get(blockIndex); if (outputStream != null) { outputStream.close(); synchronized (noSyncLengthMap) { // make sure the length of noSyncLengthMap is equal to outputStreamMap outputStreamMap.remove(blockIndex); noSyncLengthMap.remove(blockIndex); } Util.d(TAG, "OutputStream close task[" + task.getId() + "] block[" + blockIndex + "]"); } } }
2. Add in you Application.onCreate() class:
OkDownload.setSingletonInstance( new OkDownload.Builder(this) .processFileStrategy(new CustomProcessFileStrategy()) .build() );
Enjoy!
MultiPointOutputStream 中的close方法不是public,怎么复写?这个问题还有什么解决方法吗
设置单线程下载已解决
setConnectionCount(1)
设置单线程下载已解决
setConnectionCount(1)
it work
我策底解决了,哈哈哈
OkDownload Version
v1.0.2-SNAPSHOT
Problem Describe
I occur some problem, I also search on issues and wiki, I even checked the source code, but it can't help, so my real problem is:...
Log
There is the whole log from LogCat when I occur the problem(I know we can use this tool to let log more readable):