mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 02:29:24 +01:00
AdbProtocolHandler: refactor reading command from input stream
This commit is contained in:
parent
69695c5a4b
commit
4761259137
@ -48,15 +48,7 @@ class AdbProtocolHandler implements Runnable {
|
||||
}
|
||||
|
||||
private boolean processCommand(DataInput input, DataOutputStream output) throws IOException {
|
||||
byte[] buffer = new byte[4];
|
||||
input.readFully(buffer);
|
||||
String encodedLength = new String(buffer, StandardCharsets.UTF_8);
|
||||
int length = Integer.parseInt(encodedLength, 16);
|
||||
|
||||
buffer = new byte[length];
|
||||
input.readFully(buffer);
|
||||
String command = new String(buffer, StandardCharsets.UTF_8);
|
||||
|
||||
String command = readCommand(input);
|
||||
responder.onCommand(command);
|
||||
|
||||
try {
|
||||
@ -136,12 +128,21 @@ class AdbProtocolHandler implements Runnable {
|
||||
return Integer.reverseBytes(input.readInt());
|
||||
}
|
||||
|
||||
private int readHexInt(DataInput input) throws IOException {
|
||||
return Integer.parseInt(readString(input, 4), 16);
|
||||
}
|
||||
|
||||
private String readString(DataInput input, int length) throws IOException {
|
||||
byte[] responseBuffer = new byte[length];
|
||||
input.readFully(responseBuffer);
|
||||
return new String(responseBuffer, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private String readCommand(DataInput input) throws IOException {
|
||||
int length = readHexInt(input);
|
||||
return readString(input, length);
|
||||
}
|
||||
|
||||
private void sync(DataOutput output, DataInput input) throws IOException, JadbException {
|
||||
String id = readString(input, 4);
|
||||
int length = readInt(input);
|
||||
|
Loading…
Reference in New Issue
Block a user