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.
This commit is contained in:
Romain Vimont 2019-05-30 16:34:37 +02:00
parent 61f5f96b42
commit 2322069656

View file

@ -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);
}