|
|
@ -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 解密字符串 |
|
|
|
* |
|
|
|
* |
|
|
|