fix():格式规范修改

boot3.0
dongzeliang 2025-02-26 22:08:29 +08:00
parent 782ec652ed
commit e40d6fcfe2
4 changed files with 61 additions and 62 deletions

View File

@ -798,8 +798,8 @@ public class Convert {
* *
* @return . * @return .
*/ */
public static String toSBC (String input) { public static String toSbc(String input) {
return toSBC(input, null); return toSbc(input, null);
} }
/** /**
@ -810,7 +810,7 @@ public class Convert {
* *
* @return . * @return .
*/ */
public static String toSBC (String input, Set<Character> notConvertSet) { public static String toSbc(String input, Set<Character> notConvertSet) {
char[] c = input.toCharArray(); char[] c = input.toCharArray();
for (int i = 0 ; i < c.length ; i++) { for (int i = 0 ; i < c.length ; i++) {
if (null != notConvertSet && notConvertSet.contains(c[i])) { if (null != notConvertSet && notConvertSet.contains(c[i])) {

View File

@ -28,11 +28,11 @@ public class JwtUtils {
* secret, jwt * secret, jwt
* 256(32) * 256(32)
*/ */
private final static String secret = TokenConstants.SECRET; private final static String SECRET = TokenConstants.SECRET;
/** /**
* *
*/ */
public static final SecretKey KEY = Keys.hmacShaKeyFor(secret.getBytes()); public static final SecretKey KEY = Keys.hmacShaKeyFor(SECRET.getBytes());
/** /**
* jwt * jwt
*/ */

View File

@ -17,7 +17,7 @@ public class IpUtils {
// 匹配 ip // 匹配 ip
public final static String REGX_IP = "((" + REGX_0_255 + "\\.){3}" + REGX_0_255 + ")"; public final static String REGX_IP = "((" + REGX_0_255 + "\\.){3}" + REGX_0_255 + ")";
// 匹配网段 // 匹配网段
public final static String REGX_IP_SEG = "(" + REGX_IP + "\\-" + REGX_IP + ")"; public final static String REGX_IP_SEG = "(" + REGX_IP + "-" + REGX_IP + ")";
public final static String REGX_IP_WILDCARD = "(((\\*\\.){3}\\*)|(" + REGX_0_255 + "(\\.\\*){3})|(" + REGX_0_255 + "\\." + REGX_0_255 + ")(\\.\\*){2}" + "|((" + REGX_0_255 + "\\.){3}\\*))"; public final static String REGX_IP_WILDCARD = "(((\\*\\.){3}\\*)|(" + REGX_0_255 + "(\\.\\*){3})|(" + REGX_0_255 + "\\." + REGX_0_255 + ")(\\.\\*){2}" + "|((" + REGX_0_255 + "\\.){3}\\*))";
/** /**
@ -41,20 +41,20 @@ public class IpUtils {
return "unknown"; return "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.isEmpty() || "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.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Forwarded-For"); ip = request.getHeader("X-Forwarded-For");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.isEmpty() || "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.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP"); ip = request.getHeader("X-Real-IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
} }
@ -87,24 +87,23 @@ public class IpUtils {
final byte b0 = addr[0]; final byte b0 = addr[0];
final byte b1 = addr[1]; final byte b1 = addr[1];
// 10.x.x.x/8 // 10.x.x.x/8
final byte SECTION_1 = 0x0A; final byte section1 = 0x0A;
// 172.16.x.x/12 // 172.16.x.x/12
final byte SECTION_2 = (byte) 0xAC; final byte section2 = (byte) 0xAC;
final byte SECTION_3 = (byte) 0x10; final byte section3 = (byte) 0x10;
final byte SECTION_4 = (byte) 0x1F; final byte section4 = (byte) 0x1F;
// 192.168.x.x/16 // 192.168.x.x/16
final byte SECTION_5 = (byte) 0xC0; final byte section5 = (byte) 0xC0;
final byte SECTION_6 = (byte) 0xA8; final byte section6 = (byte) 0xA8;
switch (b0) { switch (b0) {
case SECTION_1: case section1:
return true; return true;
case SECTION_2: case section2:
if (b1 >= SECTION_3 && b1 <= SECTION_4) { if (b1 >= section3 && b1 <= section4) {
return true; return true;
} }
case SECTION_5: case section5:
switch (b1) { if (b1 == section6) {
case SECTION_6:
return true; return true;
} }
default: default:
@ -120,7 +119,7 @@ public class IpUtils {
* @return byte * @return byte
*/ */
public static byte[] textToNumericFormatV4 (String text) { public static byte[] textToNumericFormatV4 (String text) {
if (text.length() == 0) { if (text.isEmpty()) {
return null; return null;
} }
@ -195,7 +194,7 @@ public class IpUtils {
public static String getHostIp () { public static String getHostIp () {
try { try {
return InetAddress.getLocalHost().getHostAddress(); return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) { } catch (UnknownHostException ignored) {
} }
return "127.0.0.1"; return "127.0.0.1";
} }
@ -208,7 +207,7 @@ public class IpUtils {
public static String getHostName () { public static String getHostName () {
try { try {
return InetAddress.getLocalHost().getHostName(); return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) { } catch (UnknownHostException ignored) {
} }
return "未知"; return "未知";
} }
@ -225,7 +224,7 @@ public class IpUtils {
if (ip != null && ip.indexOf(",") > 0) { if (ip != null && ip.indexOf(",") > 0) {
final String[] ips = ip.trim().split(","); final String[] ips = ip.trim().split(",");
for (String subIp : ips) { for (String subIp : ips) {
if (false == isUnknown(subIp)) { if (!isUnknown(subIp)) {
ip = subIp; ip = subIp;
break; break;
} }

View File

@ -1,5 +1,7 @@
package com.muyu.common.core.utils.sign; package com.muyu.common.core.utils.sign;
import java.util.Arrays;
/** /**
* Base64 * Base64
* *
@ -14,40 +16,38 @@ public final class Base64 {
static private final int FOURBYTE = 4; static private final int FOURBYTE = 4;
static private final int SIGN = -128; static private final int SIGN = -128;
static private final char PAD = '='; static private final char PAD = '=';
static final private byte[] base64Alphabet = new byte[BASELENGTH]; static final private byte[] BASE_64_ALPHABET = new byte[BASELENGTH];
static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; static final private char[] LOOK_UP_BASE_64_ALPHABET = new char[LOOKUPLENGTH];
static { static {
for (int i = 0 ; i < BASELENGTH ; ++i) { Arrays.fill(BASE_64_ALPHABET, (byte) -1);
base64Alphabet[i] = -1;
}
for (int i = 'Z' ; i >= 'A' ; i--) { for (int i = 'Z' ; i >= 'A' ; i--) {
base64Alphabet[i] = (byte) (i - 'A'); BASE_64_ALPHABET[i] = (byte) (i - 'A');
} }
for (int i = 'z' ; i >= 'a' ; i--) { for (int i = 'z' ; i >= 'a' ; i--) {
base64Alphabet[i] = (byte) (i - 'a' + 26); BASE_64_ALPHABET[i] = (byte) (i - 'a' + 26);
} }
for (int i = '9' ; i >= '0' ; i--) { for (int i = '9' ; i >= '0' ; i--) {
base64Alphabet[i] = (byte) (i - '0' + 52); BASE_64_ALPHABET[i] = (byte) (i - '0' + 52);
} }
base64Alphabet['+'] = 62; BASE_64_ALPHABET['+'] = 62;
base64Alphabet['/'] = 63; BASE_64_ALPHABET['/'] = 63;
for (int i = 0 ; i <= 25 ; i++) { for (int i = 0 ; i <= 25 ; i++) {
lookUpBase64Alphabet[i] = (char) ('A' + i); LOOK_UP_BASE_64_ALPHABET[i] = (char) ('A' + i);
} }
for (int i = 26, j = 0 ; i <= 51 ; i++, j++) { for (int i = 26, j = 0 ; i <= 51 ; i++, j++) {
lookUpBase64Alphabet[i] = (char) ('a' + j); LOOK_UP_BASE_64_ALPHABET[i] = (char) ('a' + j);
} }
for (int i = 52, j = 0 ; i <= 61 ; i++, j++) { for (int i = 52, j = 0 ; i <= 61 ; i++, j++) {
lookUpBase64Alphabet[i] = (char) ('0' + j); LOOK_UP_BASE_64_ALPHABET[i] = (char) ('0' + j);
} }
lookUpBase64Alphabet[62] = (char) '+'; LOOK_UP_BASE_64_ALPHABET[62] = '+';
lookUpBase64Alphabet[63] = (char) '/'; LOOK_UP_BASE_64_ALPHABET[63] = '/';
} }
private static boolean isWhiteSpace (char octect) { private static boolean isWhiteSpace (char octect) {
@ -59,7 +59,7 @@ public final class Base64 {
} }
private static boolean isData (char octect) { private static boolean isData (char octect) {
return (octect < BASELENGTH && base64Alphabet[octect] != -1); return (octect < BASELENGTH && BASE_64_ALPHABET[octect] != -1);
} }
/** /**
@ -101,10 +101,10 @@ public final class Base64 {
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val2 | (k << 4)];
encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[(l << 2) | val3];
encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[b3 & 0x3f];
} }
// form integral number of 6-bit groups // form integral number of 6-bit groups
@ -112,8 +112,8 @@ public final class Base64 {
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
k = (byte) (b1 & 0x03); k = (byte) (b1 & 0x03);
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[k << 4];
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
} else if (fewerThan24bits == SIXTEENBIT) { } else if (fewerThan24bits == SIXTEENBIT) {
@ -125,9 +125,9 @@ public final class Base64 {
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[val2 | (k << 4)];
encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[l << 2];
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
} }
return new String(encodedData); return new String(encodedData);
@ -176,10 +176,10 @@ public final class Base64 {
return null; return null;
} // if found "no data" just return null } // if found "no data" just return null
b1 = base64Alphabet[d1]; b1 = BASE_64_ALPHABET[d1];
b2 = base64Alphabet[d2]; b2 = BASE_64_ALPHABET[d2];
b3 = base64Alphabet[d3]; b3 = BASE_64_ALPHABET[d3];
b4 = base64Alphabet[d4]; b4 = BASE_64_ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
@ -191,8 +191,8 @@ public final class Base64 {
return null; return null;
} }
b1 = base64Alphabet[d1]; b1 = BASE_64_ALPHABET[d1];
b2 = base64Alphabet[d2]; b2 = BASE_64_ALPHABET[d2];
d3 = base64Data[dataIndex++]; d3 = base64Data[dataIndex++];
d4 = base64Data[dataIndex++]; d4 = base64Data[dataIndex++];
@ -209,7 +209,7 @@ public final class Base64 {
tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
return tmp; return tmp;
} else if (!isPad(d3) && isPad(d4)) { } else if (!isPad(d3) && isPad(d4)) {
b3 = base64Alphabet[d3]; b3 = BASE_64_ALPHABET[d3];
// 最后2位应为零 // 最后2位应为零
if ((b3 & 0x3) != 0) if ((b3 & 0x3) != 0)
{ {
@ -225,8 +225,8 @@ public final class Base64 {
} }
} else { } else {
// 无衬垫 e.g 3cQl // 无衬垫 e.g 3cQl
b3 = base64Alphabet[d3]; b3 = BASE_64_ALPHABET[d3];
b4 = base64Alphabet[d4]; b4 = BASE_64_ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);