Refactor: Moving out a method

This commit is contained in:
Samuel Carlsson 2013-07-25 21:21:33 +02:00
parent b36ede6770
commit 008492e140

View File

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