【fix sonar】oConvertUtils文件

This commit is contained in:
梁琦涛
2023-03-09 17:46:25 +08:00
parent 043bd3bc75
commit 40563decf7
@@ -2,6 +2,7 @@ package com.jero.common.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
@@ -15,12 +16,11 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.sql.Date;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
@@ -54,14 +54,13 @@ public class oConvertUtils {
}
public static String decode(String strIn, String sourceCode, String targetCode) {
String temp = code2code(strIn, sourceCode, targetCode);
return temp;
return code2code(strIn, sourceCode, targetCode);
}
public static String StrToUTF() {
String strIn = "";
try {
strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
strIn = new String(strIn.getBytes(StandardCharsets.ISO_8859_1), "GBK");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -148,14 +147,6 @@ public class oConvertUtils {
return s;
}
/*public static Short getShort(String s) {
if (StringUtil.isNotEmpty(s)) {
return (Short.parseShort(s));
} else {
return null;
}
}*/
public static int getInt(Object object, int defval) {
if (isEmpty(object)) {
return (defval);
@@ -202,15 +193,6 @@ public class oConvertUtils {
return (getString(s, ""));
}
/**
* 转义成Unicode编码
* @param s
* @return
*/
/*public static String escapeJava(Object s) {
return StringEscapeUtils.escapeJava(getString(s));
}*/
public static String getString(Object object) {
if (isEmpty(object)) {
return "";
@@ -338,9 +320,9 @@ public class oConvertUtils {
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
dest = str.replace("\\s*","").replace(" ","")
.replace("\\t","").replace("\\r","")
.replace("\\n","");
}
return dest;
@@ -370,7 +352,7 @@ public class oConvertUtils {
* 获取Map对象
*/
public static Map<Object, Object> getHashMap() {
return new HashMap<Object, Object>();
return new HashMap<>();
}
/**
@@ -381,7 +363,7 @@ public class oConvertUtils {
*/
public static Map<Object, Object> SetToMap(Set<Object> setobj) {
Map<Object, Object> map = getHashMap();
for (Iterator iterator = setobj.iterator(); iterator.hasNext();) {
for (Iterator<Object> iterator = setobj.iterator(); iterator.hasNext();) {
Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
}
@@ -412,8 +394,7 @@ public class oConvertUtils {
long c = Integer.parseInt(ip[2]);
long d = Integer.parseInt(ip[3]);
long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
return ipNum;
return a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
}
private static boolean isInner(long userIp, long begin, long end) {
@@ -443,7 +424,7 @@ public class oConvertUtils {
//update-end--Author:zhoujf Date:20180503 forTASK #2500 【代码生成器】代码生成器开发一通用模板生成功能
}
// 用下划线将原始字符串分割
String camels[] = name.split("_");
String[] camels = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
@@ -506,7 +487,7 @@ public class oConvertUtils {
return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
}
// 用下划线将原始字符串分割
String camels[] = name.split("_");
String[] camels = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
@@ -646,8 +627,8 @@ public class oConvertUtils {
* list == null : true
* list.size() == 0 : true
*/
public static boolean listIsEmpty(Collection list) {
return (list == null || list.size() == 0);
public static boolean listIsEmpty(Collection<T> list) {
return (list == null || list.isEmpty());
}
/**
@@ -658,7 +639,7 @@ public class oConvertUtils {
* list == null : false
* list.size() == 0 : false
*/
public static boolean listIsNotEmpty(Collection list) {
public static boolean listIsNotEmpty(Collection<T> list) {
return !listIsEmpty(list);
}
@@ -672,7 +653,7 @@ public class oConvertUtils {
try {
//换个写法,解决springboot读取jar包中文件的问题
InputStream stream = oConvertUtils.class.getClassLoader().getResourceAsStream(url.replace("classpath:", ""));
json = IOUtils.toString(stream,"UTF-8");
json = IOUtils.toString(stream,StandardCharsets.UTF_8);
} catch (IOException e) {
log.error(e.getMessage(),e);
}