From 4bd2ff7e18f41f44a285155c8d6d8a111463b55b Mon Sep 17 00:00:00 2001 From: laoyuyu Date: Mon, 25 Apr 2022 14:19:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B=E5=8D=8E?= =?UTF-8?q?=E4=B8=BA=E6=89=8B=E6=9C=BA=E5=87=BA=E7=8E=B0=E7=9A=84=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=B8=8B=E8=BD=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AriaCompiler/build.gradle | 12 ++++---- .../aria/http/download/HttpDFileInfoTask.java | 28 ++++++++++++++----- .../core/download/HttpDownloadModule.java | 3 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/AriaCompiler/build.gradle b/AriaCompiler/build.gradle index 7ad5069d..3a3383d9 100644 --- a/AriaCompiler/build.gradle +++ b/AriaCompiler/build.gradle @@ -3,15 +3,15 @@ apply plugin: 'java' tasks.withType(JavaCompile) { options.encoding = "UTF-8" } -sourceCompatibility = JavaVersion.VERSION_1_7 -targetCompatibility = JavaVersion.VERSION_1_7 +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.google.auto:auto-common:0.10' - implementation 'com.google.auto.service:auto-service:1.0-rc6' - annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6' - implementation 'com.squareup:javapoet:1.9.0' + implementation 'com.google.auto:auto-common:1.2' + implementation 'com.google.auto.service:auto-service:1.0.1' + annotationProcessor 'com.google.auto.service:auto-service:1.0.1' + implementation 'com.squareup:javapoet:1.13.0' implementation project(':AriaAnnotations') } diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java index 91423587..135d5c65 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java @@ -19,7 +19,6 @@ import android.net.TrafficStats; import android.net.Uri; import android.os.Process; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.RequestEnum; @@ -208,6 +207,17 @@ final class HttpDFileInfoTask implements IInfoTask, Runnable { } else if (code == HttpURLConnection.HTTP_OK) { String contentType = conn.getHeaderField("Content-Type"); if (TextUtils.isEmpty(contentType)) { + if (!checkLen(len) && !isChunked) { + if (len < 0) { + failDownload( + new AriaHTTPException(String.format("任务下载失败,文件长度小于0, url: %s", mEntity.getUrl())), + false); + } + return; + } + mEntity.setFileSize(len); + mTaskWrapper.setSupportBP(true); + doNext(code, isChunked); return; } if (contentType.equals("text/html")) { @@ -254,15 +264,19 @@ final class HttpDFileInfoTask implements IInfoTask, Runnable { String.format("任务下载失败,errorCode:%s, errorMsg: %s, url: %s", code, conn.getResponseMessage(), mEntity.getUrl())), !CheckUtil.httpIsBadRequest(code)); } + if (end) { + doNext(code, isChunked); + } + } + + private void doNext(int code, boolean isChunked) { if (isStop || isCancel) { return; } - if (end) { - taskOption.setChunked(isChunked); - CompleteInfo info = new CompleteInfo(code, mTaskWrapper); - callback.onSucceed(mEntity.getUrl(), info); - mEntity.update(); - } + taskOption.setChunked(isChunked); + CompleteInfo info = new CompleteInfo(code, mTaskWrapper); + callback.onSucceed(mEntity.getUrl(), info); + mEntity.update(); } /** diff --git a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java index b68dd6cb..6ce44212 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java @@ -51,7 +51,8 @@ public class HttpDownloadModule extends BaseViewModule { //String url = AppUtil.getConfigValue(context, HTTP_URL_KEY, defUrl); //String url = "http://fdfs.speedata.cn:9989/group1/M00/00/05/rBGFrl3fdAKAVJwfMtSa9R18wLU139.zip"; //String url = "http://9.9.9.28:8088/files/update.zip"; - String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip"; + //String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip"; + String url = "https://jojopublic.tinman.cn/cc/cc-admin/course/315865800920559616.html?fileName=1463_3337.zip&checksumV2=md5Hex%3D4e42b3aacae4756079f39bbce1295a63"; //String url = "https://gitee.com/huang-junhua/iptv/raw/master/guonei.m3u8"; //String url = "http://v.kjjl100.com/kz/zx/cj/2020cjswxdb/1.mp4"; //String url = "https://static.runoob.com/images/demo/demo2.jpg";