refactor: 使用 CharSequenceUtil 替换部分 StrUtil 使用以解决 Sonar 问题

This commit is contained in:
2025-07-20 08:45:24 +08:00
parent 35e79620e4
commit ddd4e38dca
7 changed files with 22 additions and 23 deletions

View File

@@ -16,7 +16,7 @@
package top.continew.starter.json.jackson.util;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -168,7 +168,7 @@ public class JSONUtils {
* @return 解析后的 Java 对象
*/
public static <T> T parseObject(String str, Class<T> clazz) {
if (StrUtil.isEmpty(str)) {
if (CharSequenceUtil.isEmpty(str)) {
return null;
}
try {
@@ -186,7 +186,7 @@ public class JSONUtils {
* @return 解析后的 List<T>
*/
public static <T> List<T> parseArray(String str, Class<T> clazz) {
if (StrUtil.isEmpty(str)) {
if (CharSequenceUtil.isEmpty(str)) {
return new ArrayList<>();
}
try {
@@ -204,7 +204,7 @@ public class JSONUtils {
* @return 是否为 JSON 格式
*/
public static boolean isTypeJSON(String str) {
if (StrUtil.isEmpty(str)) {
if (CharSequenceUtil.isEmpty(str)) {
return false;
}
try {
@@ -223,7 +223,7 @@ public class JSONUtils {
* @return 解析后的 Java 对象
*/
public static <T> T toBean(String str, Class<T> clazz) {
if (StrUtil.isEmpty(str)) {
if (CharSequenceUtil.isEmpty(str)) {
return null;
}
try {

View File

@@ -20,9 +20,9 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.license.exception.LicenseException;
import top.continew.starter.license.model.LicenseExtraModel;
@@ -128,7 +128,7 @@ public class ServerInfoUtils {
* @return {@link String}
*/
private static String getLinuxCpuSerial() {
String result = StrUtil.EMPTY;
String result = StringConstants.EMPTY;
String cpuIdCmd = "dmidecode";
BufferedReader bufferedReader = null;
try {
@@ -160,8 +160,7 @@ public class ServerInfoUtils {
* @return {@link String}
*/
private static String getWindowCpuSerial() {
StringBuilder result = new StringBuilder(StrUtil.EMPTY);
StringBuilder result = new StringBuilder(StringConstants.EMPTY);
File file = null;
BufferedReader input = null;
try {
@@ -205,11 +204,11 @@ public class ServerInfoUtils {
try {
Process process = new ProcessBuilder("sh", "-c", command).start();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
return reader.lines().findFirst().orElse(StrUtil.EMPTY);
return reader.lines().findFirst().orElse(StringConstants.EMPTY);
}
} catch (IOException e) {
log.error("获取 Linux 主板序列号失败: {}", e.getMessage());
return StrUtil.EMPTY;
return StringConstants.EMPTY;
}
}
@@ -219,7 +218,7 @@ public class ServerInfoUtils {
* @return {@link String}
*/
private static String getWindowMainBoardSerial() {
StringBuilder result = new StringBuilder(StrUtil.EMPTY);
StringBuilder result = new StringBuilder(StringConstants.EMPTY);
File file = null;
BufferedReader input = null;
try {

View File

@@ -16,7 +16,7 @@
package top.continew.starter.storage.enums;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import top.continew.starter.core.enums.BaseEnum;
import java.util.Arrays;
@@ -69,7 +69,7 @@ public enum FileType implements BaseEnum<Integer> {
*/
public static FileType getByExtension(String extension) {
return Arrays.stream(FileType.values())
.filter(t -> t.getExtensions().contains(StrUtil.emptyIfNull(extension).toLowerCase()))
.filter(t -> t.getExtensions().contains(CharSequenceUtil.emptyIfNull(extension).toLowerCase()))
.findFirst()
.orElse(FileType.UNKNOWN);
}

View File

@@ -19,7 +19,7 @@ package top.continew.starter.storage.util;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import top.continew.starter.core.constant.StringConstants;
import java.io.ByteArrayInputStream;
@@ -121,7 +121,7 @@ public class StorageUtils {
// 获取文件的扩展名
String extName = FileNameUtil.extName(fileName);
// 去掉扩展名
String baseName = StrUtil.subBefore(fileName, StringConstants.DOT, true);
String baseName = CharSequenceUtil.subBefore(fileName, StringConstants.DOT, true);
// 拼接新的路径:原始路径 + .缩略图后缀 + .扩展名
return baseName + "." + suffix + "." + extName;
}

View File

@@ -19,8 +19,8 @@ package top.continew.starter.storage.strategy;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.exception.BusinessException;
@@ -123,7 +123,7 @@ public class LocalStorageStrategy implements StorageStrategy<LocalClient> {
// 格式化文件名 防止上传后重复
String formatFileName = StorageUtils.formatFileName(fileName);
// 判断文件路径是否为空 为空给默认路径 格式 2024/12/30/
if (StrUtil.isEmpty(path)) {
if (CharSequenceUtil.isEmpty(path)) {
path = StorageUtils.localDefaultPath();
}
// 判断文件夹是否存在 不存在则创建

View File

@@ -19,8 +19,8 @@ package top.continew.starter.storage.strategy;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -156,7 +156,7 @@ public class OssStorageStrategy implements StorageStrategy<OssClient> {
// 格式化文件名 防止上传后重复
String formatFileName = StorageUtils.formatFileName(fileName);
// 判断文件路径是否为空 为空给默认路径 格式 2024/12/30/
if (StrUtil.isEmpty(path)) {
if (CharSequenceUtil.isEmpty(path)) {
path = StorageUtils.ossDefaultPath();
}
ThumbnailResp thumbnailResp = null;

View File

@@ -16,7 +16,7 @@
package top.continew.starter.storage.util;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.text.CharSequenceUtil;
import software.amazon.awssdk.regions.Region;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.storage.constant.StorageConstant;
@@ -39,7 +39,7 @@ public class OssUtils {
* @return {@link Region }
*/
public static Region getRegion(String region) {
return StrUtil.isEmpty(region) ? Region.US_EAST_1 : Region.of(region);
return CharSequenceUtil.isEmpty(region) ? Region.US_EAST_1 : Region.of(region);
}
/**
@@ -51,7 +51,7 @@ public class OssUtils {
*/
public static String getUrl(String endpoint, String bucketName) {
// 如果是云服务商,直接返回域名或终端点
if (StrUtil.containsAny(endpoint, StorageConstant.CLOUD_SERVICE_PREFIX)) {
if (CharSequenceUtil.containsAny(endpoint, StorageConstant.CLOUD_SERVICE_PREFIX)) {
return "http://" + bucketName + StringConstants.DOT + endpoint;
} else {
return "http://" + endpoint + StringConstants.SLASH + bucketName;