From c667a0aa41c0a9f034038248455d0bfa682fbaee Mon Sep 17 00:00:00 2001 From: Samuel Carlsson Date: Thu, 25 Jul 2013 21:25:32 +0200 Subject: [PATCH] Verifying result code --- src/se/vidstige/jadb/JadbConnection.java | 14 +++++++++----- src/se/vidstige/jadb/JadbException.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/se/vidstige/jadb/JadbException.java 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; + +}