diff --git a/src/se/vidstige/jadb/JadbConnection.java b/src/se/vidstige/jadb/JadbConnection.java index 0b39b5c..1636bce 100644 --- a/src/se/vidstige/jadb/JadbConnection.java +++ b/src/se/vidstige/jadb/JadbConnection.java @@ -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 diff --git a/src/se/vidstige/jadb/JadbException.java b/src/se/vidstige/jadb/JadbException.java new file mode 100644 index 0000000..1af2eb3 --- /dev/null +++ b/src/se/vidstige/jadb/JadbException.java @@ -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; + +}