Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* @param email
* @param len The length of *
* @return The safety of Email
*/
public static String safedEmail(String email, int len) {
if(StringUtils.isNotEmpty(email))
return email.replaceAll("(.{" + len + "})(?=@)", "***");
return null;
}
/*
* For example
*
13888888888 - 138****8888
* @param phone
* @return The safety of mobile
*/
public static String safedMobile(String mobile) {
if(StringUtils.isNotEmpty(mobile))
return mobile.replaceAll("(?<=\\d{3})(.{4})(?=\\d{4})", "****");
return null;
}
/*
* For example
*
["a", "b", "c"] - a,b,c
* @param list
* @return string
*/
public static String split(List list) {
return split(list, Symbol.Comma);
}
/*
* For example
*
["a", "b", "c"] - a,b,c
* @param list
* @param split The separator default ,
* @return string
*/
public static String split(List list, String split) {
StringBuffer result = new StringBuffer();
list.forEach((item) -> result.append(item + split));
return StringUtils.removeEnd(result.toString(), split);
}
/*
* For example
*
a,b,c, - a,b,c
* @param str
* @return
*/
public static String delTail(String str){
return delTail(str, Symbol.Comma);
}
/*
* For example
*
a,b,c, - a,b,c
* @param str
* @param remove Remove the character By default ,
* @return
*/
public static String delTail(String str, String remove){
if(StringUtils.isNotEmpty(str))
return StringUtils.removeEnd(str, remove);
return "";
}
/*
* Is Chinese
* @param str
* @return boolean
*/
public static boolean isChinese(String str){
return isChinese(str, false);
}
/*
* Is Chinese
* @param str
* @return boolean
*/
public static boolean isChinese(String str, boolean hasSymbols) {
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
char c = ch[i];
if (isChinese(c, hasSymbols)) {
return true;
}
}
return false;
}
private static boolean isChinese(char c, boolean hasSymbols) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A) {
return true;
}
if (hasSymbols) {
if (ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
}
return false;
}
public static String ascii2native(String ascii) {
List ascii_s = new ArrayList();
String regex = "\\\\u[0-9,a-f,A-F]{4}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(ascii);
while (m.find()) {
ascii_s.add(m.group());
}
for (int i = 0, j = 2; i < ascii_s.size(); i++) {
String code = ascii_s.get(i).substring(j, j + 4);
char ch = (char) Integer.parseInt(code, 16);
ascii = ascii.replace(ascii_s.get(i), String.valueOf(ch));
}
return ascii;
}
public static String str2Hex(String str) throws UnsupportedEncodingException {
String hexRaw = String.format("%x", new BigInteger(1, str.getBytes("UTF-8")));
char[] hexRawArr = hexRaw.toCharArray();
StringBuilder hexFmtStr = new StringBuilder();
final String SEP = "\\x";
for (int i = 0; i < hexRawArr.length; i++) {
hexFmtStr.append(SEP).append(hexRawArr[i]).append(hexRawArr[++i]);
}
return hexFmtStr.toString();
}
public static String hex2Str(String str) throws UnsupportedEncodingException {
String strArr[] = str.split("\\\\");
byte[] byteArr = new byte[strArr.length - 1];
for (int i = 1; i < strArr.length; i++) {
Integer hexInt = Integer.decode("0" + strArr[i]);
byteArr[i - 1] = hexInt.byteValue();
}
return new String(byteArr, "UTF-8");
}
}