diff options
author | Matt Windsor <mattwindsor@btinternet.com> | 2011-03-19 14:12:44 +0000 |
---|---|---|
committer | Matt Windsor <mattwindsor@btinternet.com> | 2011-03-19 14:12:44 +0000 |
commit | 410219d08abdb859315c4d6d0e0375287d64a88b (patch) | |
tree | 3d4610f6cc671147a0aec7bca573a38d6c98b58e /src/uk/org/ury/client/Client.java | |
parent | 2efb758e7c2bd85801c76305161d9d8fa6d2be4b (diff) |
Converted protocol to JSON. Now passes its first ever unit test\!
Diffstat (limited to 'src/uk/org/ury/client/Client.java')
-rw-r--r-- | src/uk/org/ury/client/Client.java | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/uk/org/ury/client/Client.java b/src/uk/org/ury/client/Client.java index f0b2679..3d810c5 100644 --- a/src/uk/org/ury/client/Client.java +++ b/src/uk/org/ury/client/Client.java @@ -3,11 +3,15 @@ package uk.org.ury.client; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; + import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import java.util.ArrayList; -import java.util.List; + +import java.util.Map; + +import uk.org.ury.server.protocol.DecodeFailureException; +import uk.org.ury.server.protocol.ProtocolUtils; public class Client { @@ -17,15 +21,16 @@ public class Client * @param file The "file", including path and query string, to * fetch from the server. * - * @return The response from the server, as a List of lines. + * @return The response from the server, as a key-value map. + * @throws DecodeFailureException if the decode failed. */ - public List<String> - get (String file) + public Map<?, ?> + get (String file) throws DecodeFailureException { URL url = null; URLConnection uc = null; - List<String> result = new ArrayList<String> (); + String result = ""; try { @@ -51,7 +56,7 @@ public class Client inputLine != null; inputLine = in.readLine()) { - result.add (inputLine); + result += inputLine; } } catch (IOException e) @@ -60,6 +65,6 @@ public class Client e.printStackTrace (); } - return result; + return ProtocolUtils.decode (result); } } |