diff --git a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java index 4f8aac9..3f8c366 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java +++ b/austin-common/src/main/java/com/java3y/austin/common/constant/CommonConstant.java @@ -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请求内容格式 */ diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java b/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java index ce05f04..653da76 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/utils/ReadFileUtils.java @@ -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); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java index 1474d8b..0c0d885 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/DingDingRobotHandler.java @@ -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)); } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java index 4ba8cc0..dcebc20 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/kafka/ReceiverStart.java @@ -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 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; } } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java index edbadff..ab56379 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/receiver/rabbit/RabbitMqReceiver.java @@ -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; } diff --git a/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java b/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java index ef4a145..dca72f7 100644 --- a/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java +++ b/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java @@ -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 { */ 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 { */ 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; diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java index e4c4f2a..2da5a1f 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/OkHttpUtils.java @@ -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 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 entry : params.entrySet()) { + formBuilder.add(entry.getKey(), entry.getValue()); } } Request.Builder builder = getBuilderWithHeaders(headers); diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java index 71f672f..788c8cc 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/RedisUtils.java @@ -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) connection -> { for (Map.Entry 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) 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) connection -> { for (Map.Entry 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; });