Skip to content

Customizable Component

Jacksgong edited this page Jun 4, 2017 · 7 revisions

From now on, FileDownloader support following components to be customized by yourself:

Name Interface Default Impl
Connection FileDownloadConnection FileDownloadUrlConnection
OutputStream FileDownloadOutputStream FileDownloadRandomAccessFile
Database FileDownloadDatabase DefaultDatabaseImpl
ConnectionCountAdapter ConnectionCountAdapter DefaultConnectionCountAdapter

The default connection count strategy for each task, you can customize it through ConnectionCountAdapter:

  • one connection: file length [0, 1MB)
  • two connections: file length [1MB, 5MB)
  • three connections: file length [5MB, 50MB)
  • four connections: file length [50MB, 100MB)
  • five connections: file length [100MB, -)

How to valid it?

中文文档

Just create your own DownloadMgrInitialParams.InitCustomMaker and put those customized components to it, finally init the FileDownloader with it: FileDownloader#init

Step 1

Implementing your own customized component if you want. P.S: You can refer the default-impl.

Step 2

Putting it into FileDownloader when you init the FileDownloader:

FileDownloader.init(getApplicationContext(), new DownloadMgrInitialParams.InitCustomMaker()
        .database(/*You can put your customized database component here*/)
        .outputStreamCreator(/*You can put your customized output-stream component here*/)
        .connectionCreator(/*You can put your customized connection component here*/));

Others

If you want to use okhttp as your connection component, the simplest way is this repo.

Clone this wiki locally