Merge pull request #66 from xiaoxiamo/spotbugs

SpotBugs 扫描漏洞修复
pull/68/head
Java3y 5 months ago committed by GitHub
commit 3ed0470afe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -35,7 +35,7 @@ public class CommonConstant {
/**
*
*/
public static final String CHARSET_NAME = "UTF-8";
public static final String CHARSET_UTF_8 = "UTF-8";
/**
* HTTP
*/

@ -2,6 +2,8 @@ package com.java3y.austin.common.dto.account.sms;
import lombok.*;
import java.util.Objects;
/**
* <span>Form File</span>
* <p>Description</p>
@ -13,7 +15,6 @@ import lombok.*;
* @Description
* @see com.java3y.austin.common.dto.account austin
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@ -30,4 +31,36 @@ public class LinTongSmsAccount extends SmsAccount {
private String userName;
private String password;
/**
* equals
*
* @param o
* @return
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
LinTongSmsAccount that = (LinTongSmsAccount) o;
return url.equals(that.url) &&
userName.equals(that.userName) &&
password.equals(that.password);
}
/**
* hashCode
*
* @return
*/
@Override
public int hashCode() {
return Objects.hash(url, userName, password);
}
}

@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Objects;
/**
* @author 3y
*/
@ -27,5 +29,33 @@ public class SmsAccount {
*/
protected String scriptName;
/**
* equals
*
* @param o
* @return
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SmsAccount that = (SmsAccount) o;
return supplierId.equals(that.supplierId) &&
supplierName.equals(that.supplierName) &&
scriptName.equals(that.scriptName);
}
/**
* hashCode
*
* @return
*/
@Override
public int hashCode() {
return Objects.hash(supplierId, supplierName, scriptName);
}
}

@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Objects;
/**
*
* <p>
@ -42,4 +44,41 @@ public class TencentSmsAccount extends SmsAccount {
private String smsSdkAppId;
private String templateId;
private String signName;
/**
* equals
*
* @param o
* @return
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
TencentSmsAccount that = (TencentSmsAccount) o;
return url.equals(that.url) &&
region.equals(that.region) &&
secretId.equals(that.secretId) &&
secretKey.equals(that.secretKey) &&
smsSdkAppId.equals(that.smsSdkAppId) &&
templateId.equals(that.templateId) &&
signName.equals(that.signName);
}
/**
* hashCode
*
* @return
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), url, region, secretId, secretKey, smsSdkAppId, templateId, signName);
}
}

@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Objects;
/**
*
* <p>
@ -31,4 +33,36 @@ public class YunPianSmsAccount extends SmsAccount {
*/
private String url;
/**
* equals
*
* @param o
* @return
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
YunPianSmsAccount that = (YunPianSmsAccount) o;
return apikey.equals(that.apikey) &&
tplId.equals(that.tplId) &&
url.equals(that.url);
}
/**
* hashCode
*
* @return
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), apikey, tplId, url);
}
}

@ -6,6 +6,8 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
/**
* @author zzb
* @since 2021.11.17
@ -15,7 +17,7 @@ import lombok.ToString;
@ToString(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public final class BasicResultVO<T> {
public final class BasicResultVO<T> implements Serializable {
/**
*

@ -4,12 +4,16 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.csv.*;
import cn.hutool.core.util.CharsetUtil;
import com.google.common.base.Throwables;
import com.java3y.austin.cron.csv.CountFileRowHandler;
import com.java3y.austin.cron.vo.CrowdInfoVo;
import lombok.extern.slf4j.Slf4j;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
/**
@ -37,7 +41,8 @@ public class ReadFileUtils {
public static void getCsvRow(String path, CsvRowHandler csvRowHandler) {
// 把首行当做是标题获取reader
try (CsvReader reader = CsvUtil.getReader(new FileReader(path),
try (CsvReader reader = CsvUtil.getReader(
new InputStreamReader(Files.newInputStream(Paths.get(path)), CharsetUtil.CHARSET_UTF_8),
new CsvReadConfig().setContainsHeader(true))) {
reader.read(csvRowHandler);
} catch (Exception e) {
@ -54,7 +59,8 @@ public class ReadFileUtils {
public static long countCsvRow(String path, CountFileRowHandler countFileRowHandler) {
// 把首行当做是标题获取reader
try (CsvReader reader = CsvUtil.getReader(new FileReader(path),
try (CsvReader reader = CsvUtil.getReader(
new InputStreamReader(new FileInputStream(path), CharsetUtil.CHARSET_UTF_8),
new CsvReadConfig().setContainsHeader(true))) {
reader.read(countFileRowHandler);

@ -164,10 +164,12 @@ public class CronTaskServiceImpl implements CronTaskService {
}
} catch (Exception e) {
log.error("CronTaskService#getGroupId fail,e:{},param:{},response:{}", Throwables.getStackTraceAsString(e)
, JSON.toJSONString(params), JSON.toJSONString(response.body()));
, JSON.toJSONString(params),
response != null ? JSON.toJSONString(response.body()) : "");
}
invalidateCookie();
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR, JSON.toJSONString(response.body()));
return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR,
response != null ? JSON.toJSONString(response.body()) : "");
}
@Override

@ -84,7 +84,7 @@ public class XxlJobUtils {
if (Objects.isNull(basicResultVO.getData())) {
XxlJobGroup xxlJobGroup = XxlJobGroup.builder().appname(appName).title(jobHandlerName).addressType(CommonConstant.FALSE).build();
if (RespStatusEnum.SUCCESS.getCode().equals(cronTaskService.createGroup(xxlJobGroup).getStatus())) {
return (int) cronTaskService.getGroupId(appName, jobHandlerName).getData();
return (Integer) cronTaskService.getGroupId(appName, jobHandlerName).getData();
}
}
return basicResultVO.getData();

@ -32,7 +32,7 @@ public class LinTongSendResult {
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataDTO {
public static class DataDTO {
Integer code;
String message;
Long msgId;

@ -128,7 +128,7 @@ public class DingDingRobotHandler extends BaseHandler{
Mac mac = Mac.getInstance(CommonConstant.HMAC_SHA256_ENCRYPTION_ALGO);
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), CommonConstant.HMAC_SHA256_ENCRYPTION_ALGO));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), CommonConstant.CHARSET_NAME);
sign = URLEncoder.encode(new String(Base64.encodeBase64(signData), CommonConstant.CHARSET_UTF_8));
} catch (Exception e) {
log.error("DingDingHandler#assembleSign fail!:{}", Throwables.getStackTraceAsString(e));
}

@ -9,7 +9,6 @@ import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.dingtalk.api.request.OapiMessageCorpconversationGetsendresultRequest;
import com.dingtalk.api.request.OapiMessageCorpconversationRecallRequest;
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
import com.dingtalk.api.response.OapiMessageCorpconversationGetsendresultResponse;
import com.dingtalk.api.response.OapiMessageCorpconversationRecallResponse;
import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.AustinConstant;
@ -179,7 +178,7 @@ public class DingDingWorkNoticeHandler extends BaseHandler{
OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest();
req.setAgentId(Long.valueOf(account.getAgentId()));
req.setTaskId(456L);
OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, accessToken);
client.execute(req, accessToken);
} catch (Exception e) {
log.error("DingDingWorkNoticeHandler#pull fail:{}", Throwables.getStackTraceAsString(e));
}

@ -24,10 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
*
@ -44,6 +44,11 @@ public class SmsHandler extends BaseHandler{
private static final Integer AUTO_FLOW_RULE = 0;
private static final String FLOW_KEY = "msgTypeSmsConfig";
private static final String FLOW_KEY_PREFIX = "message_type_";
/**
*
*/
private static final SecureRandom secureRandom = new SecureRandom();
@Autowired
private SmsRecordDao smsRecordDao;
@Autowired
@ -99,7 +104,7 @@ public class SmsHandler extends BaseHandler{
}
// 生成一个随机数[1,total],看落到哪个区间
int index = new Random().nextInt(total) + 1;
int index = secureRandom.nextInt(total) + 1;
MessageTypeSmsConfig supplier = null;
MessageTypeSmsConfig supplierBack = null;

@ -84,14 +84,15 @@ public class ReceiverStart {
@Bean
public ConcurrentKafkaListenerContainerFactory filterContainerFactory(@Value("${austin.business.tagId.key}") String tagIdKey,
@Value("${austin.business.tagId.value}") String tagIdValue) {
ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory();
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
factory.setAckDiscarded(true);
factory.setRecordFilterStrategy(consumerRecord -> {
if (Optional.ofNullable(consumerRecord.value()).isPresent()) {
for (Header header : consumerRecord.headers()) {
if (header.key().equals(tagIdKey) && new String(header.value()).equals(new String(tagIdValue.getBytes(StandardCharsets.UTF_8)))) {
if (header.key().equals(tagIdKey) &&
new String(header.value(), StandardCharsets.UTF_8).equals(tagIdValue)) {
return false;
}
}

@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.List;
@ -42,7 +43,7 @@ public class RabbitMqReceiver implements MessageReceiver {
public void onMessage(Message message) {
String messageType = message.getMessageProperties().getHeader("messageType");
byte[] body = message.getBody();
String messageContent = new String(body);
String messageContent = new String(body, StandardCharsets.UTF_8);
if (StringUtils.isBlank(messageContent)) {
return;
}

@ -31,11 +31,14 @@ public class SendAfterCheckAction implements BusinessProcess<SendTaskModel> {
/**
*
*/
protected static final Map<Integer, String> CHANNEL_REGEX_EXP = new HashMap<>();
protected static final Map<Integer, String> CHANNEL_REGEX_EXP;
static {
CHANNEL_REGEX_EXP.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP);
CHANNEL_REGEX_EXP.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP);
Map<Integer, String> tempMap = new HashMap<>();
tempMap.put(IdType.PHONE.getCode(), PHONE_REGEX_EXP);
tempMap.put(IdType.EMAIL.getCode(), EMAIL_REGEX_EXP);
// 初始化为不可变集合,避免被恶意修改
CHANNEL_REGEX_EXP = Collections.unmodifiableMap(tempMap);
}

@ -13,6 +13,7 @@ import io.lettuce.core.RedisFuture;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
@ -50,8 +51,8 @@ public class AustinSink implements SinkFunction<AnchorInfo> {
*/
String redisMessageKey = CharSequenceUtil.join(StrPool.COLON, AustinConstant.CACHE_KEY_PREFIX, AustinConstant.MESSAGE_ID, info.getMessageId());
SimpleAnchorInfo messageAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getLogTimestamp()).build();
redisFutures.add(redisAsyncCommands.lpush(redisMessageKey.getBytes(), JSON.toJSONString(messageAnchorInfo).getBytes()));
redisFutures.add(redisAsyncCommands.expire(redisMessageKey.getBytes(), Duration.ofDays(3).toMillis() / 1000));
redisFutures.add(redisAsyncCommands.lpush(redisMessageKey.getBytes(StandardCharsets.UTF_8), JSON.toJSONString(messageAnchorInfo).getBytes(StandardCharsets.UTF_8)));
redisFutures.add(redisAsyncCommands.expire(redisMessageKey.getBytes(StandardCharsets.UTF_8), Duration.ofDays(3).toMillis() / 1000));
/**
* 1.userId list:{key,list}
@ -59,17 +60,17 @@ public class AustinSink implements SinkFunction<AnchorInfo> {
*/
SimpleAnchorInfo userAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getLogTimestamp()).build();
for (String id : info.getIds()) {
redisFutures.add(redisAsyncCommands.lpush(id.getBytes(), JSON.toJSONString(userAnchorInfo).getBytes()));
redisFutures.add(redisAsyncCommands.expire(id.getBytes(), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000));
redisFutures.add(redisAsyncCommands.lpush(id.getBytes(StandardCharsets.UTF_8), JSON.toJSONString(userAnchorInfo).getBytes(StandardCharsets.UTF_8)));
redisFutures.add(redisAsyncCommands.expire(id.getBytes(StandardCharsets.UTF_8), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000));
}
/**
* 2. hash:{key,hash}
* key:businessId,hashValue:{state,stateCount}
*/
redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(),
String.valueOf(info.getState()).getBytes(), info.getIds().size()));
redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(),
redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(StandardCharsets.UTF_8),
String.valueOf(info.getState()).getBytes(StandardCharsets.UTF_8), info.getIds().size()));
redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(StandardCharsets.UTF_8),
((DateUtil.offsetDay(new Date(), 30).getTime()) / 1000) - DateUtil.currentSeconds()));
return redisFutures;

@ -27,7 +27,7 @@ public class LettuceRedisUtils {
static {
RedisURI redisUri = RedisURI.Builder.redis(AustinFlinkConstant.REDIS_IP)
.withPort(Integer.valueOf(AustinFlinkConstant.REDIS_PORT))
.withPort(Integer.parseInt(AustinFlinkConstant.REDIS_PORT))
.withPassword(AustinFlinkConstant.REDIS_PASSWORD.toCharArray())
.build();
redisClient = RedisClient.create(redisUri);

@ -34,7 +34,6 @@ public class AustinFileUtils {
* @return
*/
public static File getRemoteUrl2File(String path, String remoteUrl) {
InputStream inputStream = null;
FileOutputStream fileOutputStream = null;
try {
@ -51,7 +50,11 @@ public class AustinFileUtils {
File file = new File(path, url.getPath());
inputStream = url.openStream();
if (!file.exists()) {
file.getParentFile().mkdirs();
boolean res = file.getParentFile().mkdirs();
if (!res) {
log.error("AustinFileUtils#getRemoteUrl2File Failed to create folder, path:{}, remoteUrl:{}", path, remoteUrl);
return null;
}
fileOutputStream = new FileOutputStream(file);
IoUtil.copy(inputStream, fileOutputStream);
}
@ -59,20 +62,8 @@ public class AustinFileUtils {
} catch (Exception e) {
log.error("AustinFileUtils#getRemoteUrl2File fail:{},remoteUrl:{}", Throwables.getStackTraceAsString(e), remoteUrl);
} finally {
if (Objects.nonNull(inputStream)) {
try {
inputStream.close();
} catch (IOException e) {
log.error("close#inputStream fail:{}", Throwables.getStackTraceAsString(e));
}
}
if (Objects.nonNull(fileOutputStream)) {
try {
fileOutputStream.close();
} catch (IOException e) {
log.error("close#fileOutputStream fail:{}", Throwables.getStackTraceAsString(e));
}
}
closeQuietly(inputStream);
closeQuietly(fileOutputStream);
}
return null;
}
@ -95,4 +86,33 @@ public class AustinFileUtils {
return files;
}
/**
* InputStream
*
* @param inputStream
*/
private static void closeQuietly(InputStream inputStream) {
if (Objects.nonNull(inputStream)) {
try {
inputStream.close();
} catch (IOException e) {
log.error("close#inputStream fail:{}", Throwables.getStackTraceAsString(e));
}
}
}
/**
* FileOutputStream
*
* @param fileOutputStream
*/
private static void closeQuietly(FileOutputStream fileOutputStream) {
if (Objects.nonNull(fileOutputStream)) {
try {
fileOutputStream.close();
} catch (IOException e) {
log.error("close#fileOutputStream fail:{}", Throwables.getStackTraceAsString(e));
}
}
}
}

@ -70,12 +70,12 @@ public class OkHttpUtils {
StringBuilder sb = new StringBuilder(url);
if (Objects.nonNull(params) && params.keySet().size() > 0) {
boolean firstFlag = true;
for (String key : params.keySet()) {
for (Map.Entry<String, String> entry : params.entrySet()) {
if (firstFlag) {
sb.append("?").append(key).append("=").append(params.get(key));
sb.append("?").append(entry.getKey()).append("=").append(entry.getValue());
firstFlag = false;
} else {
sb.append("&").append(key).append("=").append(params.get(key));
sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
}
}
@ -98,8 +98,8 @@ public class OkHttpUtils {
FormBody.Builder formBuilder = new FormBody.Builder();
if (Objects.nonNull(params) && params.keySet().size() > 0) {
for (String key : params.keySet()) {
formBuilder.add(key, params.get(key));
for (Map.Entry<String, String> entry : params.entrySet()) {
formBuilder.add(entry.getKey(), entry.getValue());
}
}
Request.Builder builder = getBuilderWithHeaders(headers);

@ -10,6 +10,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
@ -82,8 +83,8 @@ public class RedisUtils {
try {
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
connection.setEx(entry.getKey().getBytes(), seconds,
entry.getValue().getBytes());
connection.setEx(entry.getKey().getBytes(StandardCharsets.UTF_8), seconds,
entry.getValue().getBytes(StandardCharsets.UTF_8));
}
return null;
});
@ -99,8 +100,8 @@ public class RedisUtils {
public void lPush(String key, String value, Long seconds) {
try {
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
connection.lPush(key.getBytes(), value.getBytes());
connection.expire(key.getBytes(), seconds);
connection.lPush(key.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8));
connection.expire(key.getBytes(StandardCharsets.UTF_8), seconds);
return null;
});
} catch (Exception e) {
@ -142,8 +143,11 @@ public class RedisUtils {
try {
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
connection.hIncrBy(entry.getKey().getBytes(), entry.getValue().getBytes(), delta);
connection.expire(entry.getKey().getBytes(), seconds);
connection.hIncrBy(entry.getKey().getBytes(StandardCharsets.UTF_8),
entry.getValue().getBytes(StandardCharsets.UTF_8),
delta);
connection.expire(entry.getKey().getBytes(StandardCharsets.UTF_8),
seconds);
}
return null;
});

@ -13,7 +13,7 @@ import java.util.Date;
* @author 3y
*/
public class TaskInfoUtils {
private static final int TYPE_FLAG = 1000000;
private static final long TYPE_FLAG = 1000000L;
private static final String CODE = "track_code_bid";
private TaskInfoUtils() {
}
@ -34,7 +34,7 @@ public class TaskInfoUtils {
*/
public static Long generateBusinessId(Long templateId, Integer templateType) {
Integer today = Integer.valueOf(DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN));
return Long.valueOf(String.format("%d%s", templateType * TYPE_FLAG + templateId, today));
return Long.valueOf(String.format("%d%s", templateType.longValue() * TYPE_FLAG + templateId, today));
}
/**

@ -201,7 +201,11 @@ public class MessageTemplateController {
try {
File localFile = new File(filePath);
if (!localFile.exists()) {
localFile.mkdirs();
boolean res = localFile.mkdirs();
if (!res) {
log.error("MessageTemplateController#upload fail! Failed to create folder.");
throw new CommonException(RespStatusEnum.SERVICE_ERROR);
}
}
file.transferTo(localFile);
} catch (Exception e) {

@ -26,7 +26,6 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
/**
*
@ -231,62 +230,57 @@ public class Convert4Amis {
* @return
*/
public static Set<String> getPlaceholderList(String content) {
char[] textChars = content.toCharArray();
StringBuilder textSofar = new StringBuilder();
// 内容为空,直接返回
if (content == null || content.isEmpty()) {
return Collections.emptySet();
}
StringBuilder sb = new StringBuilder();
// 存储占位符 位置信息集合
List<String> placeholderList = new ArrayList<>();
// 当前标识
Set<String> placeholderSet = new HashSet<>();
int modeTg = IGNORE_TG;
for (int m = 0; m < textChars.length; m++) {
char c = textChars[m];
textSofar.append(c);
for (char c : content.toCharArray()) {
switch (c) {
case '{': {
modeTg = START_TG;
sb.append(c);
}
break;
case '$': {
case '{':
if (modeTg == IGNORE_TG) {
sb.append(c);
modeTg = START_TG;
}
break;
case '$':
if (modeTg == START_TG) {
sb.append(c);
modeTg = READ_TG;
} else {
if (modeTg == READ_TG) {
sb = new StringBuilder();
modeTg = IGNORE_TG;
}
sb.setLength(0);
modeTg = IGNORE_TG;
}
}
break;
case '}': {
break;
case '}':
if (modeTg == READ_TG) {
modeTg = IGNORE_TG;
sb.append(c);
String str = sb.toString();
if (StrUtil.isNotEmpty(str)) {
placeholderList.add(str);
textSofar = new StringBuilder();
}
sb = new StringBuilder();
String placeholder = sb.toString();
placeholderSet.add(placeholder.replaceAll("[\\{\\$\\}]", ""));
sb.setLength(0);
modeTg = IGNORE_TG;
} else if (modeTg == START_TG) {
sb.setLength(0);
modeTg = IGNORE_TG;
sb = new StringBuilder();
}
break;
}
default: {
default:
if (modeTg == READ_TG) {
sb.append(c);
} else if (modeTg == START_TG) {
sb.setLength(0);
modeTg = IGNORE_TG;
sb = new StringBuilder();
}
}
break;
}
}
Set<String> result = placeholderList.stream().map(s -> s.replaceAll("\\{", "").replaceAll("\\$", "").replaceAll("\\}", "")).collect(Collectors.toSet());
return result;
return placeholderSet;
}
/**

@ -1,18 +1,19 @@
package com.java3y.austin.web.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;
/**
* @author 3y
* multipartFile File
*/
@Slf4j
public class SpringFileUtils {
private SpringFileUtils() {
}
@ -26,23 +27,14 @@ public class SpringFileUtils {
public static File getFile(MultipartFile multipartFile) {
String fileName = multipartFile.getOriginalFilename();
File file = new File(fileName);
OutputStream out = null;
try {
out = new FileOutputStream(file);
try (OutputStream out = new FileOutputStream(file)){
byte[] ss = multipartFile.getBytes();
for (int i = 0; i < ss.length; i++) {
out.write(ss[i]);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (Objects.nonNull(out)) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
log.error("SpringFileUtils#getFile multipartFile is converted to File error:{}", e);
return null;
}
return file;
}

Loading…
Cancel
Save