Code Monkey home page Code Monkey logo

okdownload-ext's Introduction

快速解决

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.