From a625bd27a3b6f0ee99c587ae18a6e3130d754109 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Wed, 14 Nov 2018 19:32:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug=20https://github.com/AriaLyy/Aria/iss?= =?UTF-8?q?ues/319=20=E6=96=B0=E5=A2=9E201=20=E9=87=8D=E5=AE=9A=E5=90=91?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20https://github.com/AriaLyy/Aria/issues/318?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8`useServerFileName(true)?= =?UTF-8?q?`=E4=B8=AD=E5=90=AB=E6=9C=89`"`=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E5=90=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E4=BF=AE=E6=94=B9=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E7=9A=84=E4=BC=98=E5=85=88=E7=BA=A7=E4=B8=BA?= =?UTF-8?q?:=20Process.setThreadPriority(Process.THREAD=5FPRIORITY=5FBACKG?= =?UTF-8?q?ROUND);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/build.gradle | 4 +- .../aria/core/common/AbsThreadTask.java | 3 ++ .../core/common/ftp/AbsFtpInfoThread.java | 12 +++--- .../core/common/ftp/AbsFtpThreadTask.java | 8 ++-- .../common/ftp/SSLSessionReuseFTPSClient.java | 4 +- .../download/downloader/ConnectionHelp.java | 2 +- .../download/downloader/FtpDirInfoThread.java | 2 +- .../downloader/FtpFileInfoThread.java | 2 +- .../download/downloader/FtpThreadTask.java | 4 +- .../downloader/HttpFileInfoThread.java | 8 +++- .../arialyy/aria/core/queue/AbsTaskQueue.java | 2 +- .../aria/core/scheduler/AbsSchedulers.java | 5 +-- .../core/scheduler/ISchedulerListener.java | 2 +- .../upload/uploader/FtpFileInfoThread.java | 2 +- .../core/upload/uploader/FtpThreadTask.java | 6 +-- .../com/arialyy/aria/util/CommonUtil.java | 41 ++++++++++--------- .../java/com/arialyy/aria/util/ErrorHelp.java | 8 +++- AriaAnnotations/build.gradle | 2 +- AriaCompiler/build.gradle | 2 +- AriaFtpPlug/build.gradle | 2 +- .../commons/net/util/TrustManagerUtils.java | 5 ++- DEV_LOG.md | 5 +++ .../simple/download/SingleTaskActivity.java | 11 ++--- build.gradle | 4 +- gradle.properties | 2 +- 25 files changed, 84 insertions(+), 64 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index 7e21ecf5..247d08ee 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -26,8 +26,8 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile project(':AriaAnnotations') - compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' + compile 'com.arialyy.aria:aria-ftp-plug:1.0.4' // compile project(':AriaFtpPlug') } -//apply from: 'bintray-release.gradle' +apply from: 'bintray-release.gradle' diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java index 906ece5d..0214c09d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.common; +import android.os.Process; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; @@ -74,6 +75,7 @@ public abstract class AbsThreadTask 1) { - String newName = URLDecoder.decode(temp[1], "utf-8"); + String newName = URLDecoder.decode(temp[1], "utf-8").replaceAll("\"", ""); mEntity.setServerFileName(newName); renameFile(newName); break; @@ -191,11 +193,13 @@ class HttpFileInfoThread implements Runnable { } else if (code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_SEE_OTHER + || code == HttpURLConnection.HTTP_CREATED // 201 跳转 || code == 307) { handleUrlReTurn(conn, conn.getHeaderField("Location")); } else { failDownload(new AriaIOException(TAG, - String.format("任务下载失败,errorCode:%s, url: %s", code, mEntity.getUrl())), true); + String.format("任务下载失败,errorCode:%s, errorMsg: %s, url: %s", code, + conn.getResponseMessage(), mEntity.getUrl())), true); } if (end) { mTaskEntity.setChunked(isChunked); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index 27efbd20..3e1e6d85 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -76,7 +76,7 @@ abstract class AbsTaskQueue { /** * 任务失败 * - * @deprecated @see{{@link #onTaskFail(ITask, Exception)}} + * @deprecated {@link #onTaskFail(ITask, Exception)} */ @Deprecated void onTaskFail(TASK task); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java index efbceba2..406e101f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.upload.uploader; +import aria.apache.commons.net.ftp.FTPFile; import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; @@ -25,7 +26,6 @@ import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.DbHelper; import java.util.ArrayList; -import org.apache.commons.net.ftp.FTPFile; /** * Created by Aria.Lao on 2017/9/26. diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index 4ba730a8..bc9b3c42 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -15,6 +15,9 @@ */ package com.arialyy.aria.core.upload.uploader; +import aria.apache.commons.net.ftp.FTPClient; +import aria.apache.commons.net.ftp.FTPReply; +import aria.apache.commons.net.ftp.OnFtpInputStreamListener; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; @@ -27,9 +30,6 @@ import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; import java.io.IOException; import java.io.UnsupportedEncodingException; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPReply; -import org.apache.commons.net.ftp.OnFtpInputStreamListener; /** * Created by Aria.Lao on 2017/7/28. diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index c35f8c0a..cdebd34a 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -54,14 +54,17 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; +import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -352,25 +355,25 @@ public class CommonUtil { public static String convertUrl(String url) { Uri uri = Uri.parse(url); url = uri.toString(); - //if (hasDoubleCharacter(url)) { - // //预先处理空格,URLEncoder只会把空格转换为+ - // url = url.replaceAll(" ", "%20"); - // //匹配双字节字符(包括汉字在内) - // String regex = Regular.REG_DOUBLE_CHAR_AND_SPACE; - // Pattern p = Pattern.compile(regex); - // Matcher m = p.matcher(url); - // Set strs = new HashSet<>(); - // while (m.find()) { - // strs.add(m.group()); - // } - // try { - // for (String str : strs) { - // url = url.replaceAll(str, URLEncoder.encode(str, "UTF-8")); - // } - // } catch (UnsupportedEncodingException e) { - // e.printStackTrace(); - // } - //} + if (hasDoubleCharacter(url)) { + //预先处理空格,URLEncoder只会把空格转换为+ + url = url.replaceAll(" ", "%20"); + //匹配双字节字符(包括汉字在内) + String regex = Regular.REG_DOUBLE_CHAR_AND_SPACE; + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(url); + Set strs = new HashSet<>(); + while (m.find()) { + strs.add(m.group()); + } + try { + for (String str : strs) { + url = url.replaceAll(str, URLEncoder.encode(str, "UTF-8")); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } return url; } diff --git a/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java b/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java index d870f342..5f96c59c 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java @@ -47,7 +47,7 @@ public class ErrorHelp { */ private static String getLogPath() { String path = String.format("%slog/AriaCrash_%s.log", CommonUtil.getAppPath(AriaManager.APP), - getData("yyyy-MM-dd_HH:mm:ss")); + getData("yyyy-MM-dd_HH_mm_ss")); File log = new File(path); if (!log.getParentFile().exists()) { @@ -76,7 +76,11 @@ public class ErrorHelp { stringBuffer.append("\n\n"); PrintWriter writer = null; try { - writer = new PrintWriter(new FileWriter(getLogPath(), true)); + File file = new File(getLogPath()); + if(!file.exists()){ + CommonUtil.createFile(file.getPath()); + } + writer = new PrintWriter(new FileWriter(file.getPath(), true)); writer.append(stringBuffer); writer.flush(); } catch (Exception e) { diff --git a/AriaAnnotations/build.gradle b/AriaAnnotations/build.gradle index 0b581ad5..a9f2139b 100644 --- a/AriaAnnotations/build.gradle +++ b/AriaAnnotations/build.gradle @@ -11,4 +11,4 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } -//apply from: 'bintray-release.gradle' \ No newline at end of file +apply from: 'bintray-release.gradle' \ No newline at end of file diff --git a/AriaCompiler/build.gradle b/AriaCompiler/build.gradle index 38de01a1..a76e8659 100644 --- a/AriaCompiler/build.gradle +++ b/AriaCompiler/build.gradle @@ -14,4 +14,4 @@ dependencies { compile project(':AriaAnnotations') } -//apply from: 'bintray-release.gradle' \ No newline at end of file +apply from: 'bintray-release.gradle' \ No newline at end of file diff --git a/AriaFtpPlug/build.gradle b/AriaFtpPlug/build.gradle index a9f2139b..0b581ad5 100644 --- a/AriaFtpPlug/build.gradle +++ b/AriaFtpPlug/build.gradle @@ -11,4 +11,4 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } -apply from: 'bintray-release.gradle' \ No newline at end of file +//apply from: 'bintray-release.gradle' \ No newline at end of file diff --git a/AriaFtpPlug/src/main/java/aria/apache/commons/net/util/TrustManagerUtils.java b/AriaFtpPlug/src/main/java/aria/apache/commons/net/util/TrustManagerUtils.java index 63559d36..a609f284 100644 --- a/AriaFtpPlug/src/main/java/aria/apache/commons/net/util/TrustManagerUtils.java +++ b/AriaFtpPlug/src/main/java/aria/apache/commons/net/util/TrustManagerUtils.java @@ -19,9 +19,12 @@ package aria.apache.commons.net.util; import java.security.GeneralSecurityException; import java.security.KeyStore; +import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import javax.net.ssl.KeyManager; +import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; @@ -92,7 +95,7 @@ public final class TrustManagerUtils { * Return the default TrustManager provided by the JVM. *

* This should be the same as the default used by - * {@link javax.net.ssl.SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], * java.security.SecureRandom) + * {@link javax.net.ssl.SSLContext#init(KeyManager[], javax.net.ssl.TrustManager[], SecureRandom)} * SSLContext#init(KeyManager[], TrustManager[], SecureRandom)} * when the TrustManager parameter is set to {@code null} * diff --git a/DEV_LOG.md b/DEV_LOG.md index 8abd2966..3357ff74 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -9,6 +9,11 @@ } ``` - fix bug https://github.com/AriaLyy/Aria/issues/322 + - 新增201 重定向支持 https://github.com/AriaLyy/Aria/issues/318 + - 修复使用`useServerFileName(true)`中含有`"`导致的文件后缀名错误问题 + - 优化logcat日志提示 + - 修改下载线程的优先级为`Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);` + - fix bug https://github.com/AriaLyy/Aria/issues/319 + v_3.5.1 - 优化`taskExists`方法 - 添加`post`参数请求支持 diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index dafd159b..8a4c583a 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -50,7 +50,8 @@ public class SingleTaskActivity extends BaseActivity { private static final String DOWNLOAD_URL = //"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; - "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks"; + //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks"; + //"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip"; //"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip"; //"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk"; //"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 @@ -60,6 +61,7 @@ public class SingleTaskActivity extends BaseActivity { //"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1"; //"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; //"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso"; + "http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -249,7 +251,7 @@ public class SingleTaskActivity extends BaseActivity { private void startD() { //Aria.get(this).setLogLevel(ALog.LOG_CLOSE); //Aria.download(this).load("aaaa.apk"); - String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg10.apk"; + String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg11.apk"; //File file = new File(path); //if (file.exists()){ // file.delete(); @@ -261,9 +263,8 @@ public class SingleTaskActivity extends BaseActivity { //.addHeader("Accept-Encoding", "gzip, deflate") //.addHeader("DNT", "1") //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") - //.useServerFileName(true) - //.setRequestMode(RequestEnum.GET) - .setFilePath(path, false) + .useServerFileName(true) + .setFilePath(path, true) //.asPost().setParam("key", "value") //.setExtendField("{\n" // + "\"id\":\"你的样子\"\n< > " diff --git a/build.gradle b/build.gradle index 2b43b342..4aa10ef6 100644 --- a/build.gradle +++ b/build.gradle @@ -39,8 +39,8 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' -// publishVersion = '3.5.1' - publishVersion = '1.0.4' //FTP插件 + publishVersion = '3.5.2_dev' +// publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架' website = 'https://github.com/AriaLyy/Aria' diff --git a/gradle.properties b/gradle.properties index 36ed63a9..2a4e2533 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,5 +17,5 @@ #org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 # gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/ #systemProp.socksProxyHost=127.0.0.1 -#systemProp.socksProxyPort=60777 +#systemProp.socksProxyPort=1080 #systemprop.socksProxyVersion=5 \ No newline at end of file