From 14d7f0df63340ede75458c0e91b902376ef4dd64 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 20 十一月 2024 11:26:32 +0800
Subject: [PATCH] 1、优化代码;2、修改长级测试中发现的bug;3、通信中间件配置文件配置项修改

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java |  151 +++++++++++++++-----------------------------------
 1 files changed, 45 insertions(+), 106 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
index 6819327..5f05861 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
@@ -4,7 +4,50 @@
 
 
 public class ByteUtil {
-	
+
+	/**
+	 * 灏嗗瓧鑺傛暟缁勫垎鍓�
+	 * @param bytes 琚垎鍓叉暟缁�
+	 * @param fromIndex 鍒嗗壊璧峰浣嶇疆
+	 * @param len 鍒嗗壊闀垮害
+	 * @return 杩斿洖 鍒嗗壊鍑烘潵鐨勬暟缁�
+	 */
+	public static byte[] bytesSplit(byte[] bytes, int fromIndex, int len){
+		if(bytes == null){
+			return null ;
+		}else{
+			byte[] bs = new byte[len] ;
+			if(fromIndex + len > bytes.length){
+				System.arraycopy(bytes, fromIndex, bs, 0, bytes.length - fromIndex) ;
+			}else{
+				System.arraycopy(bytes, fromIndex, bs, 0, len) ;
+			}
+			return bs ;
+		}
+	}
+	/**
+	 * 灏嗗瓧鑺傛暟缁勫垎鍓�
+	 * @param bytes 琚垎鍓叉暟缁�
+	 * @param fromIndex 鍒嗗壊璧峰浣嶇疆
+	 * @param len 鍒嗗壊闀垮害
+	 * @return 杩斿洖 鍒嗗壊鍑烘潵鐨勬暟缁�
+	 */
+	public static Object[] bytesSplit_(byte[] bytes, int fromIndex, int len){
+		if(bytes == null){
+			return null ;
+		}else{
+			int realLen = len ;
+			byte[] bs = new byte[len] ;
+			if(fromIndex + len > bytes.length){
+				System.arraycopy(bytes, fromIndex, bs, 0, bytes.length - fromIndex) ;
+				realLen = bytes.length - fromIndex ;
+			}else{
+				System.arraycopy(bytes, fromIndex, bs, 0, len) ;
+			}
+			return new Object[]{bs, realLen} ;
+		}
+	}
+
 	/**
 	 * 灏嗗瓧鑺傛暟缁勫悎骞跺埌瀛楄妭鏁扮粍涓�
 	 * @param bGroup1 琚悎骞舵暟缁�
@@ -660,8 +703,7 @@
 			// s1涓嶅彉
 			s0 <<= 8;
 			s = s0 | s1;
-			return (short) s;
-
+			return (short)s ;
 		} else {
 			throw new Exception("byte2Short鏃舵暟缁勮秺鐣�");
 		}
@@ -1058,109 +1100,6 @@
 		return fromIndex ;
 	}
 
-
-
-	private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-//	/**
-//	 * 灏哹yte[]杞崲涓�16杩涘埗瀛楃涓�
-//	 *
-//	 * @param bytes 寰呰浆鎹yte[]
-//	 * @return 杩斿洖 杞崲鍚庣殑瀛楃涓�
-//	 */
-//	public static String bytesToHex(byte[] bytes) {
-//		//涓�涓猙yte涓�8浣嶏紝鍙敤涓や釜鍗佸叚杩涘埗浣嶆爣璇�
-//		char[] buf = new char[bytes.length * 2];
-//		int a = 0;
-//		int index = 0;
-//		for (byte b : bytes) { // 浣跨敤闄や笌鍙栦綑杩涜杞崲
-//			if (b < 0) {
-//				a = 256 + b;
-//			} else {
-//				a = b;
-//			}
-//
-//			buf[index++] = HEX_CHAR[a / 16];
-//			buf[index++] = HEX_CHAR[a % 16];
-//		}
-//		return new String(buf);
-//	}
-//	/**
-//	 * 灏哹yte[]杞崲涓�16杩涘埗瀛楃涓�
-//	 *
-//	 * @param bytes 寰呰浆鎹yte[]
-//	 * @return 杩斿洖 杞崲鍚庣殑瀛楃涓�
-//	 */
-//	public static String bytesToHex_BE(byte[] bytes, int startIndex, int endIndex) {
-//		byte[] bs = new byte[endIndex - startIndex + 1] ;
-//		byte j = 0 ;
-//		for(int i = startIndex; i <= endIndex; i++){
-//			bs[j++] = bytes[i] ;
-//		}
-//		//涓�涓猙yte涓�8浣嶏紝鍙敤涓や釜鍗佸叚杩涘埗浣嶆爣璇�
-//		char[] buf = new char[bs.length * 2];
-//		int a = 0;
-//		int index = 0;
-//		for (byte b : bs) { // 浣跨敤闄や笌鍙栦綑杩涜杞崲
-//			if (b < 0) {
-//				a = 256 + b;
-//			} else {
-//				a = b;
-//			}
-//
-//			buf[index++] = HEX_CHAR[a / 16];
-//			buf[index++] = HEX_CHAR[a % 16];
-//		}
-//		return new String(buf);
-//	}
-//
-//    /**
-//     * 灏哹yte[]杞崲涓�16杩涘埗瀛楃涓�
-//     *
-//     * @param bytes 寰呰浆鎹yte[]
-//     * @return 杩斿洖 杞崲鍚庣殑瀛楃涓�
-//     */
-//    public static String bytesToHex_LE(byte[] bytes, int startIndex, int endIndex) {
-//        byte[] bs = new byte[endIndex - startIndex + 1] ;
-//        byte j = 0 ;
-//        for(int i = endIndex; i >= startIndex; i--){
-//            bs[j++] = bytes[i] ;
-//        }
-//        //涓�涓猙yte涓�8浣嶏紝鍙敤涓や釜鍗佸叚杩涘埗浣嶆爣璇�
-//        char[] buf = new char[bs.length * 2];
-//        int a = 0;
-//        int index = 0;
-//        for (byte b : bs) { // 浣跨敤闄や笌鍙栦綑杩涜杞崲
-//            if (b < 0) {
-//                a = 256 + b;
-//            } else {
-//                a = b;
-//            }
-//
-//            buf[index++] = HEX_CHAR[a / 16];
-//            buf[index++] = HEX_CHAR[a % 16];
-//        }
-//        return new String(buf);
-//    }
-//
-//	/**
-//	 * 灏�16杩涘埗瀛楃涓茶浆鎹负byte[]
-//	 *
-//	 * @param str 寰呰浆鎹㈠瓧绗︿覆
-//	 * @return 杩斿洖 杞崲鍚庣殑byte[]
-//	 */
-//	public static byte[] hexToBytes(String str) {
-//		if (str == null || "".equals(str.trim())) {
-//			return new byte[0];
-//		}
-//
-//		byte[] bytes = new byte[str.length() / 2];
-//		for (int i = 0; i < str.length() / 2; i++) {
-//			String subStr = str.substring(i * 2, i * 2 + 2);
-//			bytes[i] = (byte) Integer.parseInt(subStr, 16);
-//		}
-//
-//		return bytes;
-//	}
 
 	/**
 	 * Convert char to byte

--
Gitblit v1.8.0