333bkz / okdownload-ext

收集okdownload一些问题,用于快速解决使用okdownload时的一些问题

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

快速解决

gradle引入okdownloadsqliteokdownload-ext,无论是否需要sqlite

implementation 'com.liulishuo.okdownload:okdownload:1.0.7'
implementation 'com.liulishuo.okdownload:sqlite:1.0.7'
implementation 'in.xiandan:okdownload-ext:1.0.7'

Application#onCrate调用,注意此方法会替换现有配置

OkDownloadExt.fix415Bug(this);

taskEnd使用StatusUtil.isCompleted(task)判断是否下载完成

问题详情

The current offset on block-info isn't update correct, 58953018 != 69212754 on 0

2021-06-01 21:40:31.206 9284-9284/ W/System.err: java.io.IOException: The current offset on block-info isn't update correct, 58953018 != 69212754 on 0
2021-06-01 21:40:31.206 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.file.MultiPointOutputStream.inspectComplete(MultiPointOutputStream.java:263)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.interceptor.BreakpointInterceptor.interceptFetch(BreakpointInterceptor.java:123)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.download.DownloadChain.processFetch(DownloadChain.java:220)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.interceptor.RetryInterceptor.interceptFetch(RetryInterceptor.java:57)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.download.DownloadChain.processFetch(DownloadChain.java:220)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.download.DownloadChain.start(DownloadChain.java:195)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at com.liulishuo.okdownload.core.download.DownloadChain.run(DownloadChain.java:247)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2021-06-01 21:40:31.207 9284-9284/ W/System.err:     at java.lang.Thread.run(Thread.java:919)

根据okdownload#415okdownload#425,创建CustomProcessFileStrategy

package com.liulishuo.okdownload.core.file

import com.liulishuo.okdownload.DownloadTask
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo
import com.liulishuo.okdownload.core.breakpoint.DownloadStore
import java.io.IOException

class CustomProcessFileStrategy : ProcessFileStrategy() {
    override fun createProcessStream(task: DownloadTask,
                                     info: BreakpointInfo,
                                     store: DownloadStore): MultiPointOutputStream {
        return CustomMultiPointOutputStream(task, info, store)
    }


    class CustomMultiPointOutputStream : MultiPointOutputStream {
        private var task: DownloadTask? = null

        constructor(task: DownloadTask, info: BreakpointInfo, store: DownloadStore, syncRunnable: Runnable?) : super(task, info, store, syncRunnable){
            this.task = task
        }

        constructor(task: DownloadTask, info: BreakpointInfo, store: DownloadStore) : super(task, info, store, null){
            this.task = task
        }

        @Synchronized
        @Throws(IOException::class)
        override fun close(blockIndex: Int) {
            val outputStream = outputStreamMap[blockIndex]
            if (outputStream != null) {
                outputStream.close()
                synchronized(noSyncLengthMap) {
                    // make sure the length of noSyncLengthMap is equal to outputStreamMap
                    outputStreamMap.remove(blockIndex)
                    noSyncLengthMap.remove(blockIndex)
                }
            }
        }
    }
}

Application.onCreate时设置到OkDownload实例

OkDownload.setSingletonInstance(
        new OkDownload.Builder(getApplicationContext())
                .processFileStrategy(new CustomProcessFileStrategy())
                .build());

实际未下载完成,但在taskEnd回调COMPLETED

taskEnd中使用StatusUtil.isCompleted判断是否下载完成

StatusUtil.isCompleted(task)

实际下载成功,但StatusUtil.isCompletedOrUnknown返回UNKNOWN,导致StatusUtil.isCompleted返回false

根据okdownload#244,再引入sqlite库

implementation 'com.liulishuo.okdownload:sqlite:1.0.7'

About

收集okdownload一些问题,用于快速解决使用okdownload时的一些问题

License:MIT License


Languages

Language:Java 100.0%