(ByteBuffer rawBuffer, int expectedBytes)
| 190 | } |
| 191 | |
| 192 | private boolean peekRead(ByteBuffer rawBuffer, int expectedBytes) throws IOException { |
| 193 | if (readBuffer == null) { |
| 194 | throw new IOException("读取缓冲区未初始化"); |
| 195 | } |
| 196 | |
| 197 | // 检查是否有足够的数据 |
| 198 | if (readBuffer.remaining() < expectedBytes) { |
| 199 | return false; |
| 200 | } |
| 201 | // 保存当前position |
| 202 | int originalPosition = readBuffer.position(); |
| 203 | |
| 204 | // 读取数据 |
| 205 | byte[] data = new byte[expectedBytes]; |
| 206 | readBuffer.get(data); |
| 207 | |
| 208 | this.peekPosition += expectedBytes; |
| 209 | // 恢复position |
| 210 | readBuffer.position(originalPosition); |
| 211 | rawBuffer.put(data); |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | private void handleDataTransfer(SocketChannel channel) { |
| 216 | // 数据转发已经在handleConnectionRequest中启动 |
no outgoing calls
no test coverage detected