From 85446b5b526ac53af9add7c83cfd72f39ec39611 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 07 七月 2023 10:51:13 +0800
Subject: [PATCH] 优化外联设备报警解析并上传mqtt
---
src/main/java/com/ard/utils/ByteUtils.java | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ard/utils/ByteUtils.java b/src/main/java/com/ard/utils/ByteUtils.java
index 33c7856..c121eaf 100644
--- a/src/main/java/com/ard/utils/ByteUtils.java
+++ b/src/main/java/com/ard/utils/ByteUtils.java
@@ -2,6 +2,7 @@
import javax.xml.bind.DatatypeConverter;
import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.zip.CRC32;
@@ -14,6 +15,26 @@
**/
public class ByteUtils {
/**
+ * byte鏁扮粍杞腑鏂囧瓧绗︿覆
+ */
+ public static String bytesToStringZh(byte[] bytes) {
+ String zhStr = "";
+ try {
+ int position = ByteUtils.findIndexOfDoubleZero(bytes);
+ if (position != -1) {
+ byte[] result = new byte[position];
+ System.arraycopy(bytes, 0, result, 0, position);
+ zhStr = new String(result, "GBK");
+ } else {
+ zhStr = new String(bytes, "GBK");
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return zhStr;
+ }
+
+ /**
* Byte瀛楄妭杞琀ex
*
* @param b 瀛楄妭
--
Gitblit v1.9.3