mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Refactor: Moving out a method
This commit is contained in:
parent
b36ede6770
commit
008492e140
@ -3,13 +3,9 @@ package se.vidstige.jadb;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class JadbConnection {
|
||||
@ -20,15 +16,13 @@ public class JadbConnection {
|
||||
public JadbConnection() throws UnknownHostException, IOException
|
||||
{
|
||||
_socket = new Socket("localhost", DEFAULTPORT);
|
||||
|
||||
}
|
||||
|
||||
public void getHostVersion() throws IOException {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(_socket.getOutputStream());
|
||||
send("host:version");
|
||||
|
||||
DataInput reader = new DataInputStream(_socket.getInputStream());
|
||||
writer.write("000Chost:version");
|
||||
writer.flush();
|
||||
byte[] response = new byte[4];
|
||||
byte[] response = new byte[4];
|
||||
reader.readFully(response);
|
||||
System.out.println(new String(response, Charset.forName("utf-8")));
|
||||
}
|
||||
@ -37,4 +31,15 @@ public class JadbConnection {
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
private String getCommandLength(String command) {
|
||||
return String.format("%04x", Integer.valueOf(command.length()));
|
||||
}
|
||||
|
||||
private void send(String command) throws IOException {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(_socket.getOutputStream());
|
||||
writer.write(getCommandLength(command));
|
||||
writer.write(command);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user