@Test public void testReadValidPackets() { String data = "00300123456789ABCDEF\tdevice\nFEDCBA9876543210\tdevice\n"; String result = AdbMonitor.readPacket(toByteBuffer(data)); Assert.assertEquals("0123456789ABCDEF\tdevice\nFEDCBA9876543210\tdevice\n", result); }
static String readPacket(ByteBuffer input) { if (input.remaining() < LENGTH_FIELD_SIZE) { return null; } input.get(BUFFER, 0, LENGTH_FIELD_SIZE); int length = parseLength(BUFFER); if (length > BUFFER.length) { throw new IllegalArgumentException("Packet size should not be that big: " + length); } if (input.remaining() < length) { input.rewind(); return null; } input.get(BUFFER, 0, length); return new String(BUFFER, 0, length, StandardCharsets.UTF_8); }
AdbMonitor { static String readPacket(ByteBuffer input) { if (input.remaining() < LENGTH_FIELD_SIZE) { return null; } input.get(BUFFER, 0, LENGTH_FIELD_SIZE); int length = parseLength(BUFFER); if (length > BUFFER.length) { throw new IllegalArgumentException("Packet size should not be that big: " + length); } if (input.remaining() < length) { input.rewind(); return null; } input.get(BUFFER, 0, length); return new String(BUFFER, 0, length, StandardCharsets.UTF_8); } }
AdbMonitor { static String readPacket(ByteBuffer input) { if (input.remaining() < LENGTH_FIELD_SIZE) { return null; } input.get(BUFFER, 0, LENGTH_FIELD_SIZE); int length = parseLength(BUFFER); if (length > BUFFER.length) { throw new IllegalArgumentException("Packet size should not be that big: " + length); } if (input.remaining() < length) { input.rewind(); return null; } input.get(BUFFER, 0, length); return new String(BUFFER, 0, length, StandardCharsets.UTF_8); } AdbMonitor(AdbDevicesCallback callback); }
AdbMonitor { static String readPacket(ByteBuffer input) { if (input.remaining() < LENGTH_FIELD_SIZE) { return null; } input.get(BUFFER, 0, LENGTH_FIELD_SIZE); int length = parseLength(BUFFER); if (length > BUFFER.length) { throw new IllegalArgumentException("Packet size should not be that big: " + length); } if (input.remaining() < length) { input.rewind(); return null; } input.get(BUFFER, 0, length); return new String(BUFFER, 0, length, StandardCharsets.UTF_8); } AdbMonitor(AdbDevicesCallback callback); void monitor(); }
AdbMonitor { static String readPacket(ByteBuffer input) { if (input.remaining() < LENGTH_FIELD_SIZE) { return null; } input.get(BUFFER, 0, LENGTH_FIELD_SIZE); int length = parseLength(BUFFER); if (length > BUFFER.length) { throw new IllegalArgumentException("Packet size should not be that big: " + length); } if (input.remaining() < length) { input.rewind(); return null; } input.get(BUFFER, 0, length); return new String(BUFFER, 0, length, StandardCharsets.UTF_8); } AdbMonitor(AdbDevicesCallback callback); void monitor();  }