From 2e3a206767d5042880bb6aab0964cfddd2085e39 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期三, 26 八月 2026 13:35:15 +0800
Subject: [PATCH] fix(device): 统一 BTS 帧边界解析

---
 ruoyi-device/src/main/java/com/ruoyi/device/bts/BtsTcpTransport.java |   39 ++-------------------------------------
 1 files changed, 2 insertions(+), 37 deletions(-)

diff --git a/ruoyi-device/src/main/java/com/ruoyi/device/bts/BtsTcpTransport.java b/ruoyi-device/src/main/java/com/ruoyi/device/bts/BtsTcpTransport.java
index fa9eb5e..f3d3449 100644
--- a/ruoyi-device/src/main/java/com/ruoyi/device/bts/BtsTcpTransport.java
+++ b/ruoyi-device/src/main/java/com/ruoyi/device/bts/BtsTcpTransport.java
@@ -1,6 +1,5 @@
 package com.ruoyi.device.bts;
 
-import java.io.ByteArrayOutputStream;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -83,7 +82,7 @@
             throw new BtsTransportException(BtsTransportException.Reason.DISCONNECTED,
                     "BTS disconnected before completing a response for " + host + ":" + port, ex);
         }
-        catch (ResponseTooLargeException ex)
+        catch (BtsFrameReader.FrameTooLargeException ex)
         {
             closeSocket();
             throw new BtsTransportException(BtsTransportException.Reason.RESPONSE_TOO_LARGE,
@@ -118,36 +117,7 @@
 
     private String readFrame(InputStream input) throws IOException
     {
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        int matched = 0;
-        while (true)
-        {
-            int value = input.read();
-            if (value < 0) throw new EOFException("BTS closed the connection before the response frame ended");
-            if ((byte) value == FRAME_END[matched])
-            {
-                matched++;
-                if (matched == FRAME_END.length) return decodeUtf8(buffer.toByteArray());
-                continue;
-            }
-            if (matched > 0)
-            {
-                for (int i = 0; i < matched; i++) appendPayload(buffer, FRAME_END[i]);
-                matched = 0;
-                if ((byte) value == FRAME_END[0])
-                {
-                    matched = 1;
-                    continue;
-                }
-            }
-            appendPayload(buffer, value);
-        }
-    }
-
-    private void appendPayload(ByteArrayOutputStream buffer, int value) throws ResponseTooLargeException
-    {
-        if (buffer.size() >= maxResponseBytes) throw new ResponseTooLargeException();
-        buffer.write(value);
+        return decodeUtf8(BtsFrameReader.read(input, maxResponseBytes));
     }
 
     private static String decodeUtf8(byte[] bytes) throws InvalidUtf8Exception
@@ -194,11 +164,6 @@
         {
             socket = null;
         }
-    }
-
-    private static final class ResponseTooLargeException extends IOException
-    {
-        private static final long serialVersionUID = 1L;
     }
 
     private static final class InvalidUtf8Exception extends IOException

--
Gitblit v1.7.1