Skip to content

Why Choose OkDownload

Jacksgong edited this page Aug 8, 2018 · 6 revisions

Why Rewrite FileDownloader

In fact, OkDownload is FileDownloader2, which extends all benefits from FileDownloader2 and beyond.

  • FileDownloader framework is not easy to write unit-test, it is not a testable framework, so it is not stable enough.
  • The core library of FileDownloader is too complex and not pure enough, so 6K+ star 1K+ fork with around 10 PR.

Compare to FileDownloader

  • Unit test coverage is very high which means reliable.
  • Simpler interface.
  • Task priority support.
  • Uri file to store output-stream.
  • The core library is Pure and light.
  • More flexible callback mechanism and listener.
  • More flexible to expand each part of OkDownload.
  • Fewer threads to do the same thing without drop performance.
  • File-IO thread pool is independent of Network-IO thread pool.
  • Make sense auto filename from URL if can't find from response header.
  • Cancel and Start is very effective especially for a bunch of tasks with tons of optimize.

STABILITY and RELIABLE

  • Cover unit tests as far as possible
  • Precheck whether free space is enough to store target file when try to pre-allocate length of the whole resource with PreAllocateException and EndCase.PRE_ALLOCATE_FAILED
  • Preallocate the length of the target file from disk space when start download on the very beginning
  • Cover the case of there is the same task is running/waiting on OkDownload, another one will be interrupted when required to enqueue/execute
  • Cover the case of there is a task is writing to or will be writing to the same file, another one will be interrupted when enqueue/execute or get a filename from the response.
  • It will never start completed block again automatically when you resume a task
  • It ensures the data on a block is sync and persist to the physical disk from the file system when the block-thread is finished
  • It ensures the length of data on breakpoint-store is less than or equal to the length of real data on physical disk to ensure resuming from breakpoint on the next time never damage file or loss data
  • It enables resumable for a task only if it passes ResumeAvailableLocalCheck and ResumeAvailableResponseCheck to ensure breakpoint can't damage the file and the file on the backend isn't changed
  • Cover the case of the file is changed on the backend
  • Cover the case of redirect response on okDownload
  • Fix the range automatically when a range of block is wrong
  • Check whether the local increase length is equal to the content-length on the response to make sure local data is right for each block
  • Check the first block and last block especially to cover boundary case
  • Ensure cancel operation is effective even if the connection is waiting for the response, the input stream is writing, the disconnect is very slow or breakpoint data is synching to the database
  • Ensure start operation is effective even if tons of tasks need to be started
  • Always saving proceed of each task, so the breakpoint is always resumable even if the process is killed, since your import com.liulishuo.okdownload:sqlite
  • Using trial connect to check whether resume available and get instance-length to ensure resume correct and avoid unnecessary TCP window cache before downloading each block
  • Using the content length hid on the Content-Range when there isn't valid Content-Length on the response header
  • Using another HEAD method request to check out the certain instance-length when the Content-Range and Transfer-Encoding don't exist on the response header for the trial connection.
  • Check whether the network is really available before start downloading

FLEXIBLE and PERFORMANCE

  • Support task priority
  • Support using Uri as target file reference
  • Support replace Url on BreakpointStore for the case of old Url is discard but its data still resumable
  • Combine output-streams of multi-blocks on one handler MultiPointOutputStream
  • Provide SpeedCalculator to calculate instance speed or average speed on DownloadListener
  • Provide StatusUtil to find the status of task or breakpoint-info of task anytime, anywhere
  • Provide various callback listeners to meet all requirements you want with DownloadListener1,DownloadListener2,etc..
  • Provide function to find running task reference on DownloadDispatcher#findSameTask
  • Support one task with several various listeners and manage them easily with UnifiedListenerManager
  • Support bunch listeners with DownloadListenerBunch
  • Support control batch of tasks with DownloadContext
  • Support only download on Wi-Fi network type
  • Support control the whole queue size of running task on DownloadDispatcher with DownloadDispatcher.setMaxParallelRunningCount
  • Provide DownloadSerialQueue to control dynamic serial download queue.
  • Provide DownloadContextListener to listen to the process of a bunch of tasks -- since v1.0.1-SNAPSHOT
  • Support RemitStoreOnSQLite to cover the case of many small tasks raise many useless database operations.
  • Support split any count of the block to download one task
  • Design as light as possible to download without drop performance
  • Flexible thread pools on OkDownload to let the OkDownload lighter
  • Split the network I/O thread pool and file system I/O thread pool to avoid two resources block each other
  • Support defines callback downloading process on UI-thread asynchronous or on Block-thread synchronized for each task with DownloadTask.Builder#setAutoCallbackToUIThread
  • Support defines the minimum interval millisecond between two callback of DownloadListener#fetchProgress for each task with DownloadTask.Builder#setMinIntervalMillisCallbackProcess
  • Support defines read buffer size for each task with DownloadTask.Builder#setReadBufferSize
  • Support define flush buffer size for each task with DownloadTask.Builder#setFlushBufferSize
  • Support defines sync buffer size for each task with DownloadTask.Builder#setSyncBufferSize
  • Support downloading task synchronized with DownloadTask#execute and asynchronous with DownloadTask#enqueue
  • Support customizes connection handler with implementing your own DownloadConnection and valid it with OkDownload.Builder#connectionFactory
  • Support customizes download strategy with implementing your own DownloadStrategy to determine block-count for each task, whether resumable for each task when receiving a response, whether the need to split to several blocks for each task, determine filename of task for each task, and valid it with OkDownload.Builder#downloadStrategy
  • Support customizes processing file strategy with implementing your own ProcessFileStrategy to determine how is OkDownload to handle the processing file, whether resumable when getting breakpoint info on the very beginning, and valid it with OkDownload.Builder#processFileStrategy
  • Support customizes breakpoint store by implementing your own BreakpointStore to store all resumable breakpoint info on your store and valid it with OkDownload.Builder#breakpointStore
  • Support customizes callback dispatcher with implementing your own CallbackDispatcher to handle the event of callback to DownloadListener and valid with OkDownload.Builder#callbackDispatcher
  • Support customize download dispatcher with implement your own DownloadDispatcher to control all download task
  • Support customize output stream handler by implementing your own DownloadOutputStream to control output stream for each task
  • Support register one whole download monitor to statistic all key step for each task easily with DownloadMonitor
  • Support custom Logger used on okdownload with Util.setLogger() or just want to print log on the console with Util.enableConsoleLog()
  • Support cancel and start a bunch of tasks instead of a single task with special optimizes with DownloadTask.enqueue(tasks, listener) and DownloadTask.cancel(tasks)
  • Keep cancel is efficient with let the last i/o operation flying on the background and resolve the conflict the next time for same file i/o operation with FileLock class jobs.
  • Provide various type of listener to handle different required like DownloadListener1, DownloadListener2, DownloadListener3, DownloadListener4, DownloadListener4WithSpeed
  • [] Support speed limit
  • [] Support download task on the independent process with import okdownload-process
  • [] Support RxJava
  • Support using OkHttp as connection handler with import com.liulishuo.okdownload:okhttp
  • [] Support using OkDownload on kotlin style such as DSL with import okdownload-kotlin-enhance
  • [] Provide Benchmark on benchmark application
  • Provie FileDownloader Interface wrapper for okdownload
  • Provide connectionPool library to maintain connection for default DownloadUrlConnection instead of disconnect each time
  • Support set the count of connection for each task through DownloadTask.Builder#setConnectionCount directly
  • Support set whether need to preallocate length for the file of each task through DownloadTask.Builder#setPreAllocateLength directly