Verifying result code

This commit is contained in:
Samuel Carlsson 2013-07-25 21:25:32 +02:00
parent 008492e140
commit c667a0aa41
2 changed files with 20 additions and 5 deletions

View File

@ -18,13 +18,17 @@ public class JadbConnection {
_socket = new Socket("localhost", DEFAULTPORT);
}
public void getHostVersion() throws IOException {
public void getHostVersion() throws IOException, JadbException {
send("host:version");
String response = readResponse();
if ("OKAY".equals(response) == false) throw new JadbException("command");
}
private String readResponse() throws IOException {
DataInput reader = new DataInputStream(_socket.getInputStream());
byte[] response = new byte[4];
reader.readFully(response);
System.out.println(new String(response, Charset.forName("utf-8")));
byte[] responseBuffer = new byte[4];
reader.readFully(responseBuffer);
return new String(responseBuffer, Charset.forName("utf-8"));
}
public void close() throws IOException

View File

@ -0,0 +1,11 @@
package se.vidstige.jadb;
public class JadbException extends Exception {
public JadbException(String message) {
super(message);
}
private static final long serialVersionUID = -3879283786835654165L;
}