【fix sonar】oConvertUtils文件
This commit is contained in:
+29
-17
@@ -15,6 +15,8 @@ import java.net.InetAddress;
|
|||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -27,6 +29,10 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class oConvertUtils {
|
public class oConvertUtils {
|
||||||
|
|
||||||
|
private oConvertUtils(){
|
||||||
|
|
||||||
|
}
|
||||||
public static boolean isEmpty(Object object) {
|
public static boolean isEmpty(Object object) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return (true);
|
return (true);
|
||||||
@@ -52,8 +58,8 @@ public class oConvertUtils {
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String StrToUTF(String strIn, String sourceCode, String targetCode) {
|
public static String StrToUTF() {
|
||||||
strIn = "";
|
String strIn = "";
|
||||||
try {
|
try {
|
||||||
strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
|
strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
@@ -72,7 +78,7 @@ public class oConvertUtils {
|
|||||||
try {
|
try {
|
||||||
byte[] b = strIn.getBytes(sourceCode);
|
byte[] b = strIn.getBytes(sourceCode);
|
||||||
for (int i = 0; i < b.length; i++) {
|
for (int i = 0; i < b.length; i++) {
|
||||||
System.out.print(b[i] + " ");
|
log.info(b[i] + " ");
|
||||||
}
|
}
|
||||||
strOut = new String(b, targetCode);
|
strOut = new String(b, targetCode);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -83,7 +89,7 @@ public class oConvertUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt(String s, int defval) {
|
public static int getInt(String s, int defval) {
|
||||||
if (s == null || s == "") {
|
if (s == null || "".equals(s)) {
|
||||||
return (defval);
|
return (defval);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -94,7 +100,7 @@ public class oConvertUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt(String s) {
|
public static int getInt(String s) {
|
||||||
if (s == null || s == "") {
|
if (s == null || "".equals(s)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -105,7 +111,7 @@ public class oConvertUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt(String s, Integer df) {
|
public static int getInt(String s, Integer df) {
|
||||||
if (s == null || s == "") {
|
if (s == null || "".equals(s)) {
|
||||||
return df;
|
return df;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -117,9 +123,6 @@ public class oConvertUtils {
|
|||||||
|
|
||||||
public static Integer[] getInts(String[] s) {
|
public static Integer[] getInts(String[] s) {
|
||||||
Integer[] integer = new Integer[s.length];
|
Integer[] integer = new Integer[s.length];
|
||||||
if (s == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < s.length; i++) {
|
for (int i = 0; i < s.length; i++) {
|
||||||
integer[i] = Integer.parseInt(s[i]);
|
integer[i] = Integer.parseInt(s[i]);
|
||||||
}
|
}
|
||||||
@@ -128,7 +131,7 @@ public class oConvertUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double getDouble(String s, double defval) {
|
public static double getDouble(String s, double defval) {
|
||||||
if (s == null || s == "") {
|
if (s == null || "".equals(s)) {
|
||||||
return (defval);
|
return (defval);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -268,7 +271,7 @@ public class oConvertUtils {
|
|||||||
* 要判断的类。
|
* 要判断的类。
|
||||||
* @return true 表示为基本数据类型。
|
* @return true 表示为基本数据类型。
|
||||||
*/
|
*/
|
||||||
private static boolean isBaseDataType(Class clazz) throws Exception {
|
private static boolean isBaseDataType(Class clazz) {
|
||||||
return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive());
|
return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,14 +281,15 @@ public class oConvertUtils {
|
|||||||
* @return IP Address
|
* @return IP Address
|
||||||
*/
|
*/
|
||||||
public static String getIpAddrByRequest(HttpServletRequest request) {
|
public static String getIpAddrByRequest(HttpServletRequest request) {
|
||||||
|
String unknown = "unknown";
|
||||||
String ip = request.getHeader("x-forwarded-for");
|
String ip = request.getHeader("x-forwarded-for");
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||||
ip = request.getHeader("Proxy-Client-IP");
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
}
|
}
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
}
|
}
|
||||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
|
||||||
ip = request.getRemoteAddr();
|
ip = request.getRemoteAddr();
|
||||||
}
|
}
|
||||||
return ip;
|
return ip;
|
||||||
@@ -470,7 +474,7 @@ public class oConvertUtils {
|
|||||||
if(names==null||names.equals("")){
|
if(names==null||names.equals("")){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
StringBuffer sf = new StringBuffer();
|
StringBuilder sf = new StringBuilder();
|
||||||
String[] fs = names.split(",");
|
String[] fs = names.split(",");
|
||||||
for (String field : fs) {
|
for (String field : fs) {
|
||||||
field = camelName(field);
|
field = camelName(field);
|
||||||
@@ -542,8 +546,16 @@ public class oConvertUtils {
|
|||||||
*/
|
*/
|
||||||
public static String randomGen(int place) {
|
public static String randomGen(int place) {
|
||||||
String base = "qwertyuioplkjhgfdsazxcvbnmQAZWSXEDCRFVTGBYHNUJMIKLOP0123456789";
|
String base = "qwertyuioplkjhgfdsazxcvbnmQAZWSXEDCRFVTGBYHNUJMIKLOP0123456789";
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
Random rd = new Random();
|
Random rd = null;
|
||||||
|
try {
|
||||||
|
rd = SecureRandom.getInstanceStrong();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if(Objects.isNull(rd)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for(int i=0;i<place;i++) {
|
for(int i=0;i<place;i++) {
|
||||||
sb.append(base.charAt(rd.nextInt(base.length())));
|
sb.append(base.charAt(rd.nextInt(base.length())));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user