AdbProtocolHandler: extract SyncTransport creation

This commit is contained in:
Jano Svitok 2018-07-04 12:31:27 +02:00
parent 5750321eaa
commit ebf5d6b223

View File

@ -77,7 +77,7 @@ class AdbProtocolHandler implements Runnable {
try { try {
sync(output, input); sync(output, input);
} catch (JadbException e) { // sync response with a different type of fail message } catch (JadbException e) { // sync response with a different type of fail message
SyncTransport sync = new SyncTransport(output, input); SyncTransport sync = getSyncTransport(output, input);
sync.send("FAIL", e.getMessage()); sync.send("FAIL", e.getMessage());
} }
} else if (command.startsWith("shell:")) { } else if (command.startsWith("shell:")) {
@ -148,14 +148,14 @@ class AdbProtocolHandler implements Runnable {
path = remotePath.substring(0, idx); path = remotePath.substring(0, idx);
mode = Integer.parseInt(remotePath.substring(idx + 1)); mode = Integer.parseInt(remotePath.substring(idx + 1));
} }
SyncTransport transport = new SyncTransport(output, input); SyncTransport transport = getSyncTransport(output, input);
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
transport.readChunksTo(buffer); transport.readChunksTo(buffer);
selected.filePushed(new RemoteFile(path), mode, buffer); selected.filePushed(new RemoteFile(path), mode, buffer);
transport.sendStatus("OKAY", 0); // 0 = ignored transport.sendStatus("OKAY", 0); // 0 = ignored
} else if ("RECV".equals(id)) { } else if ("RECV".equals(id)) {
String remotePath = readString(input, length); String remotePath = readString(input, length);
SyncTransport transport = new SyncTransport(output, input); SyncTransport transport = getSyncTransport(output, input);
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
selected.filePulled(new RemoteFile(remotePath), buffer); selected.filePulled(new RemoteFile(remotePath), buffer);
transport.sendStream(new ByteArrayInputStream(buffer.toByteArray())); transport.sendStream(new ByteArrayInputStream(buffer.toByteArray()));
@ -171,4 +171,8 @@ class AdbProtocolHandler implements Runnable {
writer.writeBytes(getCommandLength(response)); writer.writeBytes(getCommandLength(response));
writer.writeBytes(response); writer.writeBytes(response);
} }
private SyncTransport getSyncTransport(DataOutput output, DataInput input) {
return new SyncTransport(output, input);
}
} }