style: 应用 Spotless 代码格式化
- 对所有 Java 源文件应用统一的代码格式化 - 统一缩进为 4 个空格 - 清理尾随空白字符和文件末尾换行 - 优化导入语句组织 - 总计格式化 654 个 Java 文件 有问题可以回滚或者找我聊
This commit is contained in:
@@ -24,8 +24,10 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的加法运算。
|
||||
*
|
||||
* @param v1 被加数
|
||||
* @param v2 加数
|
||||
* @param v1
|
||||
* 被加数
|
||||
* @param v2
|
||||
* 加数
|
||||
* @return 两个参数的和
|
||||
*/
|
||||
public static double add(double v1, double v2) {
|
||||
@@ -37,8 +39,10 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的减法运算。
|
||||
*
|
||||
* @param v1 被减数
|
||||
* @param v2 减数
|
||||
* @param v1
|
||||
* 被减数
|
||||
* @param v2
|
||||
* 减数
|
||||
* @return 两个参数的差
|
||||
*/
|
||||
public static double sub(double v1, double v2) {
|
||||
@@ -50,8 +54,10 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的乘法运算。
|
||||
*
|
||||
* @param v1 被乘数
|
||||
* @param v2 乘数
|
||||
* @param v1
|
||||
* 被乘数
|
||||
* @param v2
|
||||
* 乘数
|
||||
* @return 两个参数的积
|
||||
*/
|
||||
public static double mul(double v1, double v2) {
|
||||
@@ -61,11 +67,12 @@ public class Arith {
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到
|
||||
* 小数点以后10位,以后的数字四舍五入。
|
||||
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后10位,以后的数字四舍五入。
|
||||
*
|
||||
* @param v1 被除数
|
||||
* @param v2 除数
|
||||
* @param v1
|
||||
* 被除数
|
||||
* @param v2
|
||||
* 除数
|
||||
* @return 两个参数的商
|
||||
*/
|
||||
public static double div(double v1, double v2) {
|
||||
@@ -73,18 +80,19 @@ public class Arith {
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指
|
||||
* 定精度,以后的数字四舍五入。
|
||||
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
|
||||
*
|
||||
* @param v1 被除数
|
||||
* @param v2 除数
|
||||
* @param scale 表示表示需要精确到小数点以后几位。
|
||||
* @param v1
|
||||
* 被除数
|
||||
* @param v2
|
||||
* 除数
|
||||
* @param scale
|
||||
* 表示表示需要精确到小数点以后几位。
|
||||
* @return 两个参数的商
|
||||
*/
|
||||
public static double div(double v1, double v2, int scale) {
|
||||
if (scale < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"The scale must be a positive integer or zero");
|
||||
throw new IllegalArgumentException("The scale must be a positive integer or zero");
|
||||
}
|
||||
BigDecimal b1 = new BigDecimal(Double.toString(v1));
|
||||
BigDecimal b2 = new BigDecimal(Double.toString(v2));
|
||||
@@ -97,14 +105,15 @@ public class Arith {
|
||||
/**
|
||||
* 提供精确的小数位四舍五入处理。
|
||||
*
|
||||
* @param v 需要四舍五入的数字
|
||||
* @param scale 小数点后保留几位
|
||||
* @param v
|
||||
* 需要四舍五入的数字
|
||||
* @param scale
|
||||
* 小数点后保留几位
|
||||
* @return 四舍五入后的结果
|
||||
*/
|
||||
public static double round(double v, int scale) {
|
||||
if (scale < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"The scale must be a positive integer or zero");
|
||||
throw new IllegalArgumentException("The scale must be a positive integer or zero");
|
||||
}
|
||||
BigDecimal b = new BigDecimal(Double.toString(v));
|
||||
BigDecimal one = BigDecimal.ONE;
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
|
||||
import com.starry.common.domain.Captcha;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -14,6 +10,8 @@ import java.net.URL;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
|
||||
/**
|
||||
* @author 拼图验证码工具类
|
||||
@@ -110,7 +108,8 @@ public class CaptchaUtils {
|
||||
/**
|
||||
* 抠图,并生成阻塞块
|
||||
**/
|
||||
public static void cutByTemplate(BufferedImage canvasImage, BufferedImage blockImage, int blockWidth, int blockHeight, int blockRadius, int blockX, int blockY) {
|
||||
public static void cutByTemplate(BufferedImage canvasImage, BufferedImage blockImage, int blockWidth,
|
||||
int blockHeight, int blockRadius, int blockX, int blockY) {
|
||||
BufferedImage waterImage = new BufferedImage(blockWidth, blockHeight, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
// 阻塞块的轮廓图
|
||||
int[][] blockData = getBlockData(blockWidth, blockHeight, blockRadius);
|
||||
@@ -124,7 +123,8 @@ public class CaptchaUtils {
|
||||
waterImage.setRGB(i, j, Color.BLACK.getRGB());
|
||||
blockImage.setRGB(i, j, canvasImage.getRGB(blockX + i, blockY + j));
|
||||
// 轮廓设置为白色,取带像素和无像素的界点,判断该点是不是临界轮廓点
|
||||
if (blockData[i + 1][j] == 0 || blockData[i][j + 1] == 0 || blockData[i - 1][j] == 0 || blockData[i][j - 1] == 0) {
|
||||
if (blockData[i + 1][j] == 0 || blockData[i][j + 1] == 0 || blockData[i - 1][j] == 0
|
||||
|| blockData[i][j - 1] == 0) {
|
||||
blockImage.setRGB(i, j, Color.WHITE.getRGB());
|
||||
waterImage.setRGB(i, j, Color.WHITE.getRGB());
|
||||
}
|
||||
@@ -169,7 +169,8 @@ public class CaptchaUtils {
|
||||
for (int j = 0; j < blockHeight; j++) {
|
||||
data[i][j] = 0;
|
||||
// 创建中间的方形区域
|
||||
if ((i >= blockRadius && i <= blockWidth - blockRadius && j >= blockRadius && j <= blockHeight - blockRadius)) {
|
||||
if ((i >= blockRadius && i <= blockWidth - blockRadius && j >= blockRadius
|
||||
&& j <= blockHeight - blockRadius)) {
|
||||
data[i][j] = 1;
|
||||
}
|
||||
double d1 = Math.pow(i - Objects.requireNonNull(circle1)[0], 2) + Math.pow(j - circle1[1], 2);
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
@@ -14,7 +12,6 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class ConvertUtil {
|
||||
|
||||
|
||||
public static <T> T entityToVo(Object source, Class<T> target) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
@@ -11,6 +7,9 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import javax.net.ssl.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用http发送方法
|
||||
@@ -23,7 +22,8 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url) {
|
||||
@@ -33,8 +33,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param) {
|
||||
@@ -44,9 +46,12 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType 编码类型
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType
|
||||
* 编码类型
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param, String contentType) {
|
||||
@@ -90,8 +95,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendPost(String url, String param) {
|
||||
@@ -205,4 +212,4 @@ public class HttpUtils {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import cn.hutool.core.util.RandomUtil;
|
||||
**/
|
||||
public class IdUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 生成8位的UUID
|
||||
*
|
||||
|
||||
@@ -5,6 +5,10 @@ package com.starry.common.utils;
|
||||
* @since 2024/7/25 下午3:15
|
||||
**/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.lionsoul.ip2region.DataBlock;
|
||||
@@ -13,11 +17,6 @@ import org.lionsoul.ip2region.DbSearcher;
|
||||
import org.lionsoul.ip2region.Util;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 根据ip离线查询地址
|
||||
*
|
||||
@@ -74,16 +73,16 @@ public class RegionUtils {
|
||||
int algorithm = DbSearcher.MEMORY_ALGORITYM;
|
||||
Method method = null;
|
||||
switch (algorithm) {
|
||||
case DbSearcher.BTREE_ALGORITHM:
|
||||
case DbSearcher.BTREE_ALGORITHM :
|
||||
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||
break;
|
||||
case DbSearcher.BINARY_ALGORITHM:
|
||||
case DbSearcher.BINARY_ALGORITHM :
|
||||
method = searcher.getClass().getMethod("binarySearch", String.class);
|
||||
break;
|
||||
case DbSearcher.MEMORY_ALGORITYM:
|
||||
case DbSearcher.MEMORY_ALGORITYM :
|
||||
method = searcher.getClass().getMethod("memorySearch", String.class);
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
@@ -103,4 +102,4 @@ public class RegionUtils {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
@@ -91,8 +89,10 @@ public class ServletUtils {
|
||||
/**
|
||||
* 将字符串渲染到客户端
|
||||
*
|
||||
* @param response 渲染对象
|
||||
* @param string 待渲染的字符串
|
||||
* @param response
|
||||
* 渲染对象
|
||||
* @param string
|
||||
* 待渲染的字符串
|
||||
*/
|
||||
public static void renderString(HttpServletResponse response, String string) {
|
||||
try {
|
||||
@@ -110,34 +110,27 @@ public class ServletUtils {
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
/*public static boolean isAjaxRequest(HttpServletRequest request)
|
||||
{
|
||||
String accept = request.getHeader("accept");
|
||||
if (accept != null && accept.contains("application/json"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ajax = request.getParameter("__ajax");
|
||||
return StringUtils.inStringIgnoreCase(ajax, "json", "xml");
|
||||
}*/
|
||||
/*
|
||||
* public static boolean isAjaxRequest(HttpServletRequest request) { String
|
||||
* accept = request.getHeader("accept"); if (accept != null &&
|
||||
* accept.contains("application/json")) { return true; }
|
||||
*
|
||||
* String xRequestedWith = request.getHeader("X-Requested-With"); if
|
||||
* (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) {
|
||||
* return true; }
|
||||
*
|
||||
* String uri = request.getRequestURI(); if (StringUtils.inStringIgnoreCase(uri,
|
||||
* ".json", ".xml")) { return true; }
|
||||
*
|
||||
* String ajax = request.getParameter("__ajax"); return
|
||||
* StringUtils.inStringIgnoreCase(ajax, "json", "xml"); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* 内容编码
|
||||
*
|
||||
* @param str 内容
|
||||
* @param str
|
||||
* 内容
|
||||
* @return 编码后的内容
|
||||
*/
|
||||
public static String urlEncode(String str) {
|
||||
@@ -151,7 +144,8 @@ public class ServletUtils {
|
||||
/**
|
||||
* 内容解码
|
||||
*
|
||||
* @param str 内容
|
||||
* @param str
|
||||
* 内容
|
||||
* @return 解码后的内容
|
||||
*/
|
||||
public static String urlDecode(String str) {
|
||||
|
||||
@@ -9,8 +9,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* spring工具类 方便在非spring管理环境中获取bean
|
||||
* @author admin spring工具类 方便在非spring管理环境中获取bean
|
||||
* @since 2022/7/28
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 字符串工具类
|
||||
* @author admin 字符串工具类
|
||||
* @since 2022/7/19
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
@@ -22,7 +20,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
*/
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
|
||||
/**
|
||||
* 驼峰转下划线命名
|
||||
*/
|
||||
@@ -65,7 +62,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个对象是否为空
|
||||
*
|
||||
* @param object Object
|
||||
* @param object
|
||||
* Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object) {
|
||||
@@ -75,8 +73,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个对象是否非空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
* @param object
|
||||
* Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotNull(Object object) {
|
||||
return !isNull(object);
|
||||
@@ -85,8 +84,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个对象数组是否为空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* * @return true:为空 false:非空
|
||||
* @param objects
|
||||
* 要判断的对象数组 * @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Object[] objects) {
|
||||
return isNull(objects) || (objects.length == 0);
|
||||
@@ -95,7 +94,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @param map
|
||||
* 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map) {
|
||||
@@ -105,7 +105,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @param map
|
||||
* 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map) {
|
||||
@@ -115,7 +116,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Collection是否非空,包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @param coll
|
||||
* 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll) {
|
||||
@@ -125,7 +127,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @param coll
|
||||
* 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll) {
|
||||
@@ -141,8 +144,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
|
||||
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
|
||||
*
|
||||
* @param template 文本模板,被替换的部分用 {} 表示
|
||||
* @param params 参数值
|
||||
* @param template
|
||||
* 文本模板,被替换的部分用 {} 表示
|
||||
* @param params
|
||||
* 参数值
|
||||
* @return 格式化后的文本
|
||||
*/
|
||||
public static String format(String template, Object... params) {
|
||||
@@ -155,8 +160,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
/**
|
||||
* 判断给定的set列表中是否包含数组array 判断给定的数组array中是否包含给定的元素value
|
||||
*
|
||||
* @param collection 给定的集合
|
||||
* @param array 给定的数组
|
||||
* @param collection
|
||||
* 给定的集合
|
||||
* @param array
|
||||
* 给定的数组
|
||||
* @return boolean 结果
|
||||
*/
|
||||
public static boolean containsAny(Collection<String> collection, String... array) {
|
||||
@@ -199,10 +206,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
|
||||
* 例如:HELLO_WORLD -> HelloWorld
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD ->
|
||||
* HelloWorld
|
||||
*
|
||||
* @param name 转换前的下划线大写方式命名的字符串
|
||||
* @param name
|
||||
* 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
public static String convertToCamelCase(String name) {
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package com.starry.common.utils;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 线程相关工具类
|
||||
* @author admin 线程相关工具类
|
||||
* @since 2022/7/25
|
||||
*/
|
||||
public class ThreadsUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ThreadsUtils.class);
|
||||
|
||||
/**
|
||||
* 停止线程池
|
||||
* 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
|
||||
* 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数.
|
||||
* 如果仍然超時,則強制退出.
|
||||
* 另对在shutdown时线程本身被调用中断做了处理.
|
||||
* 停止线程池 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务. 如果超时, 则调用shutdownNow,
|
||||
* 取消在workQueue中Pending的任务,并中断所有阻塞函数. 如果仍然超時,則強制退出. 另对在shutdown时线程本身被调用中断做了处理.
|
||||
*/
|
||||
public static void shutdownAndAwaitTermination(ExecutorService pool) {
|
||||
if (pool != null && !pool.isShutdown()) {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.starry.common.utils.file;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 文件上传工具类
|
||||
* @author admin 文件上传工具类
|
||||
* @since 2022/10/28
|
||||
*/
|
||||
public class FileUploadUtils {
|
||||
@@ -29,5 +27,4 @@ public class FileUploadUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.starry.common.utils.html;
|
||||
|
||||
|
||||
import com.starry.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -29,7 +28,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* 转义文本中的HTML字符为安全的字符
|
||||
*
|
||||
* @param text 被转义的文本
|
||||
* @param text
|
||||
* 被转义的文本
|
||||
* @return 转义后的文本
|
||||
*/
|
||||
public static String escape(String text) {
|
||||
@@ -39,7 +39,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* 还原被转义的HTML特殊字符
|
||||
*
|
||||
* @param content 包含转义符的HTML内容
|
||||
* @param content
|
||||
* 包含转义符的HTML内容
|
||||
* @return 转换后的字符串
|
||||
*/
|
||||
public static String unescape(String content) {
|
||||
@@ -49,7 +50,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* 清除所有HTML标签,但是不删除标签内的内容
|
||||
*
|
||||
* @param content 文本
|
||||
* @param content
|
||||
* 文本
|
||||
* @return 清除标签后的文本
|
||||
*/
|
||||
public static String clean(String content) {
|
||||
@@ -59,7 +61,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* Escape编码
|
||||
*
|
||||
* @param text 被编码的文本
|
||||
* @param text
|
||||
* 被编码的文本
|
||||
* @return 编码后的字符
|
||||
*/
|
||||
private static String encode(String text) {
|
||||
@@ -83,7 +86,8 @@ public class EscapeUtil {
|
||||
/**
|
||||
* Escape解码
|
||||
*
|
||||
* @param content 被转义的内容
|
||||
* @param content
|
||||
* 被转义的内容
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
public static String decode(String content) {
|
||||
|
||||
@@ -58,7 +58,8 @@ public final class HTMLFilter {
|
||||
**/
|
||||
private final String[] vSelfClosingTags;
|
||||
/**
|
||||
* html elements which must always have separate opening and closing tags (e.g. "<b></b>")
|
||||
* html elements which must always have separate opening and closing tags (e.g.
|
||||
* "<b></b>")
|
||||
**/
|
||||
private final String[] vNeedClosingTags;
|
||||
/**
|
||||
@@ -74,7 +75,8 @@ public final class HTMLFilter {
|
||||
**/
|
||||
private final String[] vAllowedProtocols;
|
||||
/**
|
||||
* tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />")
|
||||
* tags which should be removed if they contain no content (e.g. "<b></b>" or
|
||||
* "<b />")
|
||||
**/
|
||||
private final String[] vRemoveBlanks;
|
||||
/**
|
||||
@@ -87,8 +89,9 @@ public final class HTMLFilter {
|
||||
private final boolean stripComment;
|
||||
private final boolean encodeQuotes;
|
||||
/**
|
||||
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "<b text </b>"
|
||||
* becomes "<b> text </b>"). If set to false, unbalanced angle brackets will be html escaped.
|
||||
* flag determining whether to try to make tags when presented with "unbalanced"
|
||||
* angle brackets (e.g. "<b text </b>" becomes "<b> text </b>"). If set to
|
||||
* false, unbalanced angle brackets will be html escaped.
|
||||
*/
|
||||
private final boolean alwaysMakeTags;
|
||||
|
||||
@@ -131,7 +134,8 @@ public final class HTMLFilter {
|
||||
/**
|
||||
* Map-parameter configurable constructor.
|
||||
*
|
||||
* @param conf map containing configuration. keys match field names.
|
||||
* @param conf
|
||||
* map containing configuration. keys match field names.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public HTMLFilter(final Map<String, Object> conf) {
|
||||
@@ -194,10 +198,13 @@ public final class HTMLFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* given a user submitted input String, filter out any invalid or restricted html.
|
||||
* given a user submitted input String, filter out any invalid or restricted
|
||||
* html.
|
||||
*
|
||||
* @param input text (i.e. submitted by a user) than may contain html
|
||||
* @return "clean" version of input, with only valid, whitelisted html elements allowed
|
||||
* @param input
|
||||
* text (i.e. submitted by a user) than may contain html
|
||||
* @return "clean" version of input, with only valid, whitelisted html elements
|
||||
* allowed
|
||||
*/
|
||||
public String filter(final String input) {
|
||||
reset();
|
||||
@@ -326,7 +333,8 @@ public final class HTMLFilter {
|
||||
final String body = m.group(2);
|
||||
String ending = m.group(3);
|
||||
|
||||
// debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
|
||||
// debug( "in a starting tag, name='" + name + "'; body='" + body + "';
|
||||
// ending='" + ending + "'" );
|
||||
if (allowed(name)) {
|
||||
final StringBuilder params = new StringBuilder();
|
||||
|
||||
@@ -494,4 +502,4 @@ public final class HTMLFilter {
|
||||
private boolean allowedAttribute(final String name, final String paramName) {
|
||||
return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.starry.common.utils.http;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import javax.servlet.ServletRequest;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用http工具封装
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package com.starry.common.utils.http;
|
||||
|
||||
import com.starry.common.constant.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
@@ -12,6 +8,9 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
import javax.net.ssl.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 通用http发送方法
|
||||
@@ -24,8 +23,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param) {
|
||||
@@ -35,9 +36,12 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType 编码类型
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType
|
||||
* 编码类型
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param, String contentType) {
|
||||
@@ -81,8 +85,10 @@ public class HttpUtils {
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param url
|
||||
* 发送请求的 URL
|
||||
* @param param
|
||||
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendPost(String url, String param) {
|
||||
@@ -196,4 +202,4 @@ public class HttpUtils {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.starry.common.utils.ip;
|
||||
|
||||
|
||||
import com.starry.common.utils.RegionUtils;
|
||||
import com.starry.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* 获取地址工具类
|
||||
* @author admin 获取地址工具类
|
||||
* @since 2022/7/25
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.starry.common.utils.ip;
|
||||
|
||||
|
||||
import com.starry.common.utils.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 获取IP方法
|
||||
@@ -16,7 +14,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 获取客户端IP
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @param request
|
||||
* 请求对象
|
||||
* @return IP地址
|
||||
*/
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
@@ -47,7 +46,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 检查是否为内部IP地址
|
||||
*
|
||||
* @param ip IP地址
|
||||
* @param ip
|
||||
* IP地址
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean internalIp(String ip) {
|
||||
@@ -58,7 +58,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 检查是否为内部IP地址
|
||||
*
|
||||
* @param addr byte地址
|
||||
* @param addr
|
||||
* byte地址
|
||||
* @return 结果
|
||||
*/
|
||||
private static boolean internalIp(byte[] addr) {
|
||||
@@ -77,18 +78,18 @@ public class IpUtils {
|
||||
final byte SECTION_5 = (byte) 0xC0;
|
||||
final byte SECTION_6 = (byte) 0xA8;
|
||||
switch (b0) {
|
||||
case SECTION_1:
|
||||
case SECTION_1 :
|
||||
return true;
|
||||
case SECTION_2:
|
||||
case SECTION_2 :
|
||||
if (b1 >= SECTION_3 && b1 <= SECTION_4) {
|
||||
return true;
|
||||
}
|
||||
case SECTION_5:
|
||||
case SECTION_5 :
|
||||
switch (b1) {
|
||||
case SECTION_6:
|
||||
case SECTION_6 :
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
default :
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -96,7 +97,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 将IPv4地址转换成字节
|
||||
*
|
||||
* @param text IPv4地址
|
||||
* @param text
|
||||
* IPv4地址
|
||||
* @return byte 字节
|
||||
*/
|
||||
public static byte[] textToNumericFormatV4(String text) {
|
||||
@@ -110,7 +112,7 @@ public class IpUtils {
|
||||
long l;
|
||||
int i;
|
||||
switch (elements.length) {
|
||||
case 1:
|
||||
case 1 :
|
||||
l = Long.parseLong(elements[0]);
|
||||
if ((l < 0L) || (l > 4294967295L)) {
|
||||
return null;
|
||||
@@ -120,7 +122,7 @@ public class IpUtils {
|
||||
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
||||
bytes[3] = (byte) (int) (l & 0xFF);
|
||||
break;
|
||||
case 2:
|
||||
case 2 :
|
||||
l = Integer.parseInt(elements[0]);
|
||||
if ((l < 0L) || (l > 255L)) {
|
||||
return null;
|
||||
@@ -134,7 +136,7 @@ public class IpUtils {
|
||||
bytes[2] = (byte) (int) ((l & 0xFFFF) >> 8 & 0xFF);
|
||||
bytes[3] = (byte) (int) (l & 0xFF);
|
||||
break;
|
||||
case 3:
|
||||
case 3 :
|
||||
for (i = 0; i < 2; ++i) {
|
||||
l = Integer.parseInt(elements[i]);
|
||||
if ((l < 0L) || (l > 255L)) {
|
||||
@@ -149,7 +151,7 @@ public class IpUtils {
|
||||
bytes[2] = (byte) (int) (l >> 8 & 0xFF);
|
||||
bytes[3] = (byte) (int) (l & 0xFF);
|
||||
break;
|
||||
case 4:
|
||||
case 4 :
|
||||
for (i = 0; i < 4; ++i) {
|
||||
l = Integer.parseInt(elements[i]);
|
||||
if ((l < 0L) || (l > 255L)) {
|
||||
@@ -158,7 +160,7 @@ public class IpUtils {
|
||||
bytes[i] = (byte) (int) (l & 0xFF);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
return null;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -196,7 +198,8 @@ public class IpUtils {
|
||||
/**
|
||||
* 从多级反向代理中获得第一个非unknown IP地址
|
||||
*
|
||||
* @param ip 获得的IP地址
|
||||
* @param ip
|
||||
* 获得的IP地址
|
||||
* @return 第一个非unknown IP地址
|
||||
*/
|
||||
public static String getMultistageReverseProxyIp(String ip) {
|
||||
@@ -216,10 +219,11 @@ public class IpUtils {
|
||||
/**
|
||||
* 检测给定字符串是否为未知,多用于检测HTTP请求相关
|
||||
*
|
||||
* @param checkString 被检测的字符串
|
||||
* @param checkString
|
||||
* 被检测的字符串
|
||||
* @return 是否未知
|
||||
*/
|
||||
public static boolean isUnknown(String checkString) {
|
||||
return StringUtils.isBlank(checkString) || "unknown".equalsIgnoreCase(checkString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user