Merge branch 'v_3.0'

pull/330/head
AriaLyy 7 years ago
commit 699590cecc
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  3. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  4. 46
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  5. 1
      app/src/main/java/com/arialyy/simple/MainActivity.java

@ -297,7 +297,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private void handleBreakpoint() { private void handleBreakpoint() {
long fileLength = mEntity.getFileSize(); long fileLength = mEntity.getFileSize();
Properties pro = CommonUtil.loadConfig(mConfigFile); Properties pro = CommonUtil.loadConfig(mConfigFile);
int blockSize = (int) (fileLength / mThreadNum); long blockSize = fileLength / mThreadNum;
int[] recordL = new int[mThreadNum]; int[] recordL = new int[mThreadNum];
for (int i = 0; i < mThreadNum; i++) { for (int i = 0; i < mThreadNum; i++) {
recordL[i] = -1; recordL[i] = -1;

@ -20,12 +20,12 @@ import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.downloader.ConnectionHelp;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder;
/** /**
* 下载文件信息获取 * 下载文件信息获取
@ -48,7 +48,7 @@ class HttpFileInfoThread implements Runnable {
@Override public void run() { @Override public void run() {
HttpURLConnection conn = null; HttpURLConnection conn = null;
try { try {
URL url = new URL(mEntity.getUrl()); URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl()));
conn = ConnectionHelp.handleConnection(url); conn = ConnectionHelp.handleConnection(url);
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
conn.setRequestProperty("Range", "bytes=" + 0 + "-"); 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.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -47,7 +48,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
InputStream is = null; InputStream is = null;
BufferedRandomAccessFile file = null; BufferedRandomAccessFile file = null;
try { try {
URL url = new URL(mConfig.URL); URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
conn = ConnectionHelp.handleConnection(url); conn = ConnectionHelp.handleConnection(url);
if (mConfig.SUPPORT_BP) { if (mConfig.SUPPORT_BP) {
Log.d(TAG, "任务【" Log.d(TAG, "任务【"

@ -42,15 +42,18 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.lang.reflect.GenericArrayType; import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@ -64,6 +67,49 @@ import java.lang.reflect.WildcardType;
public class CommonUtil { public class CommonUtil {
private static final String TAG = "CommonUtil"; private static final String TAG = "CommonUtil";
/**
* 转换Url
*
* @param url 原地址
* @return 转换后的地址
*/
public static String convertUrl(String url) {
if (hasDoubleCharacter(url)) {
//匹配双字节字符(包括汉字在内)
String regex = "[^\\x00-\\xff]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(url);
Set<String> 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;
}
/**
* 判断是否有双字节字符(包括汉字在内)
*
* @param chineseStr 需要进行判断的字符串
* @return {@code true}有双字节字符{@code false} 无双字节字符
*/
public static boolean hasDoubleCharacter(String chineseStr) {
char[] charArray = chineseStr.toCharArray();
for (char aCharArray : charArray) {
if ((aCharArray >= 0x0391) && (aCharArray <= 0xFFE5)) {
return true;
}
}
return false;
}
/** /**
* base64 解密字符串 * base64 解密字符串
* *

@ -70,4 +70,5 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
break; break;
} }
} }
} }

Loading…
Cancel
Save