From a1dbfa1c66d113137fab5517edafa9fb4ec4ff3c Mon Sep 17 00:00:00 2001 From: Jacksgong Date: Tue, 5 Apr 2016 20:16:15 +0800 Subject: [PATCH] chore(upgrade): upgrade version name(0.2.0->0.2.1) code(11->12) --- CHANGELOG-ZH.md | 28 ++++++++++++++++++++++++++++ CHANGELOG.md | 27 +++++++++++++++++++++++++++ README-zh.md | 24 +++++++++++++++++++----- README.md | 23 ++++++++++++++++++----- gradle.properties | 4 ++-- 5 files changed, 94 insertions(+), 12 deletions(-) diff --git a/CHANGELOG-ZH.md b/CHANGELOG-ZH.md index 0b44b001..b403245f 100644 --- a/CHANGELOG-ZH.md +++ b/CHANGELOG-ZH.md @@ -1,5 +1,33 @@ # Change log +> [ Change log in english](https://github.com/lingochamp/FileDownloader/blob/master/CHANGELOG.md) + +## Version 0.2.1 + +_2016-04-05_ + +#### 新接口 + +- 添加 `FileDownloadHttpException` 与 `FileDownloadGiveUpRetryException`, 优化异常回调处理机制. Closes #67 。 +- 初始化 `FileDownloader` 传入参数由原来需要 `Application` 改为 需要 `Context`( `FileDownloader#init(Context)` ), 优化接口,并且便于单元测试。 Closes #54 。 + +#### 性能与提高 + +- 提高稳定性: 在开始获取数据之前,先检查是否有足够的空间用于存储下载文件,如果不够直接抛异常,如果足够将锁定对应空间用于正常存储正在下载的文件。 Closes #46 。 +- 提高实用性: 断点续传支持,不再强制要求Etag存在;支持不需要Etag,只要后台支持 `Range` 头部参数就可以支持断点续传。 Close #35 , #66 。 + +#### 修复 + +- 修复: 在 `FileDownloadLog.NEED_LOG` 为 `true` 时,并且事件无效的情况下,`EventPool` 出现 `IllegalFormatConversionException` 异常的问题。 Closes #30 。 +- 修复: 在 Filedownloader进程被杀以后, 在 `IFileDownloadIPCService` 出现异常。Closes #38 。 +- 修复: 修复 reponse-body 可能存在的泄漏: 'WARNING: A connection to https://... was leaked. Did you forget to close a response body?' Closes #68 。 +- 修复: 使用 `internal-string` 作为同步的对象,而非直接用 String对象。 +- 修复: 在一些情况下如果存在重复任务,在高并发下进行中的回调次数可能不对的bug。 + +#### 其他 + +- 所依赖的okhttp从`3.1.2`升到`3.2.0`。 + ## Version 0.2.0 _2016-02-15_ diff --git a/CHANGELOG.md b/CHANGELOG.md index 68be3123..7b87c45f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ > [中文迭代日志](https://github.com/lingochamp/FileDownloader/blob/master/CHANGELOG-ZH.md) +## Version 0.2.1 + +_2016-04-05_ + +#### New Interfaces + +- Add `FileDownloadHttpException` and `FileDownloadGiveUpRetryException`, and optimize the mechanism of exception. Closes #67 . +- Init the `FileDownloader` use `Context` instead of `Application` ( `FileDownloader#init(Context)` ) , for more make sense and unit-test. Closes #54 . + +#### Enhancement + +- Improve Robust: Check whether free space is enough, and throw IOException directly when not enough; And pre-allocate need-available-space before fetching datum when the free space more than need-available-space. Closes #46 . +- Improve Practicability: Support resume from breakpoint without ETag. Just need the server support the request-header param 'Range'. Close #35 , #66 . + + +#### Fix + +- Fix: The `IllegalFormatConversionException` on `EventPool` when publishing the event which does not in effect and `FileDownloadLog.NEED_LOG` is `true`. Closes #30 . +- Fix: The non-fatal-crash in `IFileDownloadIPCService.java` , when lost connection from filedownloader process. because the IBinder's hosting process(filedownloader process) has been killed/cancelled. Closes #38 . +- Fix: The leak of response-body: 'WARNING: A connection to https://... was leaked. Did you forget to close a response body?' Closes #68 . +- Fix: Using the internal-string as synchronized lock-object instead of string-original. +- Fix: The number of the Ing-call-back is not correct in some cases. + +#### Others + +- Upgrade dependency okhttp from `3.1.2` to `3.2.0`. + ## Version 0.2.0 _2016-02-15_ diff --git a/README-zh.md b/README-zh.md index bf302fec..d4e3cbe1 100644 --- a/README-zh.md +++ b/README-zh.md @@ -7,7 +7,7 @@ Android 文件下载引擎,稳定、高效、简单易用 > [README DOC](https://github.com/lingochamp/FileDownloader/blob/master/README.md) -> 本引擎依赖okhttp 3.1.2 +> 本引擎依赖okhttp 3.2.0 --- #### 版本迭代日志: [Change Log](https://github.com/lingochamp/FileDownloader/blob/master/CHANGELOG.md) @@ -46,7 +46,7 @@ Android 文件下载引擎,稳定、高效、简单易用 在项目中引用: ``` -compile 'com.liulishuo.filedownloader:library:0.2.0' +compile 'com.liulishuo.filedownloader:library:0.2.1' ``` #### 全局初始化在`Application.onCreate`中 @@ -59,8 +59,10 @@ public XXApplication extends Application{ ... @Override public void onCreate() { - // 不耗时,仅仅只是缓存下Application的Context不会启动下载进程 - FileDownloader.init(this); + /** + * 仅仅是缓存Application的Context,不耗时 + */ + FileDownloader.init(getApplicationContext); } ... @@ -214,7 +216,8 @@ if (parallel) { | 方法名 | 备注 | --- | --- -| init(Application) | 简单初始化,不会启动下载进程 +| init(Context) | 缓存Context,不会启动下载进程 +| init(Context, OkHttpClientCustomMaker) | 缓存Context,不会启动下载进程;在下载进程启动的时候,初始化OkHttpClient | create(url:String) | 创建一个下载任务 | start(listener:FileDownloadListener, isSerial:boolean) | 启动是相同监听器的任务,串行/并行启动 | pause(listener:FileDownloadListener) | 暂停启动相同监听器的任务 @@ -359,6 +362,17 @@ blockComplete -> completed | http.lenient | 如果你遇到了: 'can't know the size of the download file, and its Transfer-Encoding is not Chunked either', 但是你想要忽略类似的返回头不规范的错误,直接将该关键字参数设置为`true`即可,我们将会将其作为`chunck`进行处理 | false +III. 异常处理 + +> 所有的异常,都将在 `FileDownloadListener#error(BaseDownloadTask, Throwable)` 中获知。 + +| Exception | 原因 +| --- | --- +| `FileDownloadHttpException`| 在发出请求以后,response-code不是200(HTTP_OK),也不是206(HTTP_PARTIAL)的情况下会抛出该异常; 在这个异常对象会带上 response-code、response-header、request-header。 +| `FileDownloadGiveUpRetryException` | 在请求返回的 response-header 中没有带有文件大小(content-length),并且不是流媒体(transfer-encoding)的情况下会抛出该异常;出现这个异常,将会忽略所有重试的机会(`BaseDownloadTask#setAutoRetryTimes`). 你可以通过在 `filedownloader.properties`中添加 `http.lenient=true` 来忽略这个异常,并且在该情况下,直接作为流媒体进行下载。 +| 其他 | 程序错误; 或者是本地的存储空间已经不足以存储将要下载的文件会直接抛出`IOException` 。 + + ## III. 低内存情况 diff --git a/README.md b/README.md index 4bb7b726..9ffb0a95 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Android multi-task file download engine. > [中文文档](https://github.com/lingochamp/FileDownloader/blob/master/README-zh.md) -> This project dependency on [square/okhttp 3.1.2](https://github.com/square/okhttp) +> This project dependency on [square/okhttp 3.2.0](https://github.com/square/okhttp) ## DEMO @@ -26,7 +26,7 @@ FileDownloader is installed by adding the following dependency to your build.gra ``` dependencies { - compile 'com.liulishuo.filedownloader:library:0.2.0' + compile 'com.liulishuo.filedownloader:library:0.2.1' } ``` @@ -45,8 +45,11 @@ public XXApplication extends Application{ @Override public void onCreate() { super.onCreate(); - // Just cache Application's Context. - FileDownloader.init(this); + /** + * Just for cache Application's Context, and ':filedownloader' progress will NOT be launched + * by below code, so please do not worry about performance. + */ + FileDownloader.init(getApplicationContext()); } ... @@ -212,7 +215,8 @@ queueSet.start(); | function | description | --- | --- -| init(Application) | Just cache ApplicationContext +| init(Context) | Just cache `Context` in Main-Process and FileDownloader-Process. +| init(Context, OkHttpClientCustomMaker) | Cache `Context` in Main-Process and FileDownloader-Process, and init the OkHttpClient in FileDownloader-Process when FileDownloader-Process is launching. | create(url:String) | Create a download task | start(listener:FileDownloadListener, isSerial:boolean) | Start the download queue by the same listener(maybe do not need callback each task's `FileDownloadListener#progress` in this case, then set `setCallbackProgressTimes(0)` is effective optimization) | pause(listener:FileDownloadListener) | Pause the download queue by the same listener @@ -355,6 +359,15 @@ blockComplete -> completed | --- | --- | --- | http.lenient | if you occur exception: 'can't know the size of the download file, and its Transfer-Encoding is not Chunked either', but you want to ignore such exception, set true, will deal with it as the case of transfer encoding chunk. | false +## Exception + +> If occur a exception, you will get it in `FileDownloadListener#error(BaseDownloadTask, Throwable)` + +| Exception | reason +| --- | --- +| `FileDownloadHttpException`| Throw this exception, when the HTTP status code is not 200(HTTP_OK), and not 206(HTTP_PARTIAL) either. You can find the request-header, the response-header and response-code in this exception. +| `FileDownloadGiveUpRetryException` | Throw this exception, when can't know the size of the download file, and its Transfer-Encoding is not Chunked either; And With this exception, will ignore all retry-chances(`BaseDownloadTask#setAutoRetryTimes`). You can ignore such exception by add `http.lenient=true` to the `filedownloader.properties`, and will download directly as a Chunked-Resource. +| Others | Program Exception, or the free space is not enough to store the download-file will throw the `IOException` . ## Attention diff --git a/gradle.properties b/gradle.properties index 5434f85b..088a88d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -VERSION_NAME=0.2.0 -VERSION_CODE=11 +VERSION_NAME=0.2.1 +VERSION_CODE=12 BUILD_TOOLS_VERSION=23.0.1 COMPILE_SDK_VERSION=23