AriaLyy 7 years ago
parent 063a0e95c2
commit 9290b2c466
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  2. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  3. 32
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.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 + "-");

@ -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<DownloadEntity, DownloadTaskEnt
InputStream is = null;
BufferedRandomAccessFile file = null;
try {
URL url = new URL(mConfig.URL);
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
conn = ConnectionHelp.handleConnection(url);
if (mConfig.SUPPORT_BP) {
Log.d(TAG, "任务【"

@ -42,6 +42,7 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@ -64,6 +65,37 @@ import java.lang.reflect.WildcardType;
public class CommonUtil {
private static final String TAG = "CommonUtil";
/**
* 转换Url
*
* @param url 原地址
* @return 转换后的地址
*/
public static String convertUrl(String url) {
try {
return hasChineseCharacter(url) ? URLEncoder.encode(url, "UTF-8") : url;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
/**
* 判断是否有中文
*
* @param chineseStr 需要进行判断的字符串
* @return {@code true}有中文{@code false} 无中文
*/
public static boolean hasChineseCharacter(String chineseStr) {
char[] charArray = chineseStr.toCharArray();
for (char aCharArray : charArray) {
if ((aCharArray >= 0x4e00) && (aCharArray <= 0x9fbb)) {
return true;
}
}
return false;
}
/**
* base64 解密字符串
*

Loading…
Cancel
Save