From 9290b2c466f5d7a531776cf24647c71a74247c14 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Fri, 4 Aug 2017 18:57:30 +0800 Subject: [PATCH 1/4] fix https://github.com/AriaLyy/Aria/issues/88 --- .../downloader/HttpFileInfoThread.java | 4 +-- .../download/downloader/HttpThreadTask.java | 3 +- .../com/arialyy/aria/util/CommonUtil.java | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 51ce3611..07103531 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -20,12 +20,12 @@ import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; -import com.arialyy.aria.core.download.downloader.ConnectionHelp; import com.arialyy.aria.util.CommonUtil; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLDecoder; +import java.net.URLEncoder; /** * 下载文件信息获取 @@ -48,7 +48,7 @@ class HttpFileInfoThread implements Runnable { @Override public void run() { HttpURLConnection conn = null; try { - URL url = new URL(mEntity.getUrl()); + URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl())); conn = ConnectionHelp.handleConnection(url); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index 09d76523..03265590 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -23,6 +23,7 @@ import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.util.BufferedRandomAccessFile; +import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -47,7 +48,7 @@ final class HttpThreadTask extends AbsThreadTask= 0x4e00) && (aCharArray <= 0x9fbb)) { + return true; + } + } + return false; + } + /** * base64 解密字符串 * From 17c0caedd9dac30e296e686d1179e700034f1e30 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Mon, 7 Aug 2017 11:18:01 +0800 Subject: [PATCH 2/4] fix bug https://github.com/AriaLyy/Aria/issues/88 --- .../com/arialyy/aria/util/CommonUtil.java | 30 ++++++++++++++----- .../java/com/arialyy/simple/MainActivity.java | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) 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 e58a3537..b9cf605c 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -47,11 +47,13 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; import java.util.Set; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; @@ -72,24 +74,36 @@ public class CommonUtil { * @return 转换后的地址 */ public static String convertUrl(String url) { - try { - return hasChineseCharacter(url) ? URLEncoder.encode(url, "UTF-8") : url; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + if (hasChineseCharacter(url)) { + //匹配双字节字符(包括汉字在内) + String regex = "[^\\x00-\\xff]"; + 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 ""; + return url; } /** - * 判断是否有中文 + * 判断是否有双字节字符(包括汉字在内) * * @param chineseStr 需要进行判断的字符串 - * @return {@code true}有中文,{@code false} 无中文 + * @return {@code true}有双字节字符,{@code false} 无双字节字符 */ public static boolean hasChineseCharacter(String chineseStr) { char[] charArray = chineseStr.toCharArray(); for (char aCharArray : charArray) { - if ((aCharArray >= 0x4e00) && (aCharArray <= 0x9fbb)) { + if (aCharArray <= 0xff) { return true; } } diff --git a/app/src/main/java/com/arialyy/simple/MainActivity.java b/app/src/main/java/com/arialyy/simple/MainActivity.java index 8a8a7cd6..dc0012a7 100644 --- a/app/src/main/java/com/arialyy/simple/MainActivity.java +++ b/app/src/main/java/com/arialyy/simple/MainActivity.java @@ -70,4 +70,5 @@ public class MainActivity extends BaseActivity { break; } } + } From f546ebb7cbff9877becb7ec873778a6b9ba0abbc Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Mon, 7 Aug 2017 11:30:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=8C=E5=AD=97?= =?UTF-8?q?=E8=8A=82=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 b9cf605c..021bbbb8 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -74,7 +74,7 @@ public class CommonUtil { * @return 转换后的地址 */ public static String convertUrl(String url) { - if (hasChineseCharacter(url)) { + if (hasDoubleCharacter(url)) { //匹配双字节字符(包括汉字在内) String regex = "[^\\x00-\\xff]"; Pattern p = Pattern.compile(regex); @@ -100,10 +100,10 @@ public class CommonUtil { * @param chineseStr 需要进行判断的字符串 * @return {@code true}有双字节字符,{@code false} 无双字节字符 */ - public static boolean hasChineseCharacter(String chineseStr) { + public static boolean hasDoubleCharacter(String chineseStr) { char[] charArray = chineseStr.toCharArray(); for (char aCharArray : charArray) { - if (aCharArray <= 0xff) { + if ((aCharArray >= 0x0391) && (aCharArray <= 0xFFE5)) { return true; } } From a3f6e174e319634a0cf7ec0b4667193f24b3fd84 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Mon, 7 Aug 2017 17:33:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=95=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=8C=BA=E9=97=B4=E5=A4=A7=E4=BA=8E2=E4=B8=AAG?= =?UTF-8?q?=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84=E4=B8=8D=E8=83=BD=E4=B8=8B?= =?UTF-8?q?=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 --- Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index f263e22c..db24b141 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -297,7 +297,7 @@ public abstract class AbsFileer