From 092d7c56bb8653075b8f4b27220e69e6bb8e5d37 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期四, 09 十一月 2023 16:49:26 +0800
Subject: [PATCH] 增加超脑业务
---
src/main/java/com/ard/utils/other/ByteUtils.java | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ard/utils/other/ByteUtils.java b/src/main/java/com/ard/utils/other/ByteUtils.java
index bda4b8c..0c11f68 100644
--- a/src/main/java/com/ard/utils/other/ByteUtils.java
+++ b/src/main/java/com/ard/utils/other/ByteUtils.java
@@ -30,13 +30,27 @@
* byte鏁扮粍杞腑鏂囧瓧绗︿覆
*/
public static String bytesToStringZh(byte[] bytes) {
- ByteBuffer buffer = ByteBuffer.wrap(bytes); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
+ //ByteBuffer buffer = ByteBuffer.wrap(bytes); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
+ //try {
+ // return new String(buffer.array(), "GBK");
+ //} catch (UnsupportedEncodingException e) {
+ // e.printStackTrace();
+ //}
+ //return "";
+ String zhStr = "";
try {
- return new String(buffer.array(), "GBK");
+ 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 "";
+ return zhStr;
}
/**
@@ -67,8 +81,13 @@
* byte鏁扮粍杞暣鍨�
*/
public static int bytesToDecimal(byte[] byteArray) {
- ByteBuffer buffer = ByteBuffer.wrap(byteArray); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
- return buffer.getInt();
+ //ByteBuffer buffer = ByteBuffer.wrap(byteArray); // byteArray 鏄寘鍚瓧鑺傛暟缁勭殑鍙橀噺
+ //return buffer.getInt();
+ int decimalValue = 0;
+ for (int i = 0; i < byteArray.length; i++) {
+ decimalValue = (decimalValue << 8) | (byteArray[i] & 0xFF);
+ }
+ return decimalValue;
}
--
Gitblit v1.9.3