From 232206965671f921a1d5a881e2b28f63aff1eb72 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 30 May 2019 16:34:37 +0200 Subject: [PATCH] Extract control event String parsing Parsing a String from a serialized control event, encoded as length (2 bytes) + data, will be necessary in several events. Extract it to a separate method. --- .../com/genymobile/scrcpy/ControlEventReader.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java b/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java index 8eeea27c..c48b1826 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java +++ b/server/src/main/java/com/genymobile/scrcpy/ControlEventReader.java @@ -92,7 +92,7 @@ public class ControlEventReader { return ControlEvent.createKeycodeControlEvent(action, keycode, metaState); } - private ControlEvent parseTextControlEvent() { + private String parseString() { if (buffer.remaining() < 2) { return null; } @@ -101,7 +101,14 @@ public class ControlEventReader { return null; } buffer.get(textBuffer, 0, len); - String text = new String(textBuffer, 0, len, StandardCharsets.UTF_8); + return new String(textBuffer, 0, len, StandardCharsets.UTF_8); + } + + private ControlEvent parseTextControlEvent() { + String text = parseString(); + if (text == null) { + return null; + } return ControlEvent.createTextControlEvent(text); }