copy from ruoyi-device/src/main/java/com/ruoyi/device/bts/ScriptedBtsTcpSimulator.java
copy to battery-device-simulator/src/main/java/com/battery/device/simulator/ScriptedBtsTcpSimulator.java
| File was copied from ruoyi-device/src/main/java/com/ruoyi/device/bts/ScriptedBtsTcpSimulator.java |
| | |
| | | package com.ruoyi.device.bts; |
| | | package com.battery.device.simulator; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | |
| | | |
| | | private String readFrame(InputStream input) throws IOException |
| | | { |
| | | return new String(BtsFrameReader.read(input, Integer.MAX_VALUE), StandardCharsets.UTF_8); |
| | | return new String(readFrameBytes(input), StandardCharsets.UTF_8); |
| | | } |
| | | |
| | | private byte[] readFrameBytes(InputStream input) throws IOException |
| | | { |
| | | java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream(); |
| | | byte[] delimiter = FRAME_END; |
| | | int matched = 0; |
| | | while (true) |
| | | { |
| | | int current = input.read(); |
| | | if (current < 0) throw new java.io.EOFException("BTS frame ended before delimiter"); |
| | | if ((byte) current == delimiter[matched]) |
| | | { |
| | | matched++; |
| | | if (matched == delimiter.length) return bytes.toByteArray(); |
| | | continue; |
| | | } |
| | | if (matched > 0) |
| | | { |
| | | for (int i = 0; i < matched; i++) bytes.write(delimiter[i]); |
| | | matched = 0; |
| | | if ((byte) current == delimiter[0]) |
| | | { |
| | | matched = 1; |
| | | continue; |
| | | } |
| | | } |
| | | bytes.write(current); |
| | | } |
| | | } |
| | | |
| | | @Override |