mirror of
https://github.com/revanced/jadb.git
synced 2025-05-29 04:50:12 +02: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.DataInput;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.CharBuffer;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
public class JadbConnection {
|
public class JadbConnection {
|
||||||
@ -20,15 +16,13 @@ public class JadbConnection {
|
|||||||
public JadbConnection() throws UnknownHostException, IOException
|
public JadbConnection() throws UnknownHostException, IOException
|
||||||
{
|
{
|
||||||
_socket = new Socket("localhost", DEFAULTPORT);
|
_socket = new Socket("localhost", DEFAULTPORT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getHostVersion() throws IOException {
|
public void getHostVersion() throws IOException {
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(_socket.getOutputStream());
|
send("host:version");
|
||||||
|
|
||||||
DataInput reader = new DataInputStream(_socket.getInputStream());
|
DataInput reader = new DataInputStream(_socket.getInputStream());
|
||||||
writer.write("000Chost:version");
|
byte[] response = new byte[4];
|
||||||
writer.flush();
|
|
||||||
byte[] response = new byte[4];
|
|
||||||
reader.readFully(response);
|
reader.readFully(response);
|
||||||
System.out.println(new String(response, Charset.forName("utf-8")));
|
System.out.println(new String(response, Charset.forName("utf-8")));
|
||||||
}
|
}
|
||||||
@ -37,4 +31,15 @@ public class JadbConnection {
|
|||||||
{
|
{
|
||||||
_socket.close();
|
_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…
x
Reference in New Issue
Block a user