blob: f0b2679b76dafcd8eae71d2d3903adc11d0451d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
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;
public class Client
{
/**
* Get a raw response from the server.
*
* @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.
*/
public List<String>
get (String file)
{
URL url = null;
URLConnection uc = null;
List<String> result = new ArrayList<String> ();
try
{
url = new URL ("http://localhost:8000" + file);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
try
{
uc = url.openConnection ();
BufferedReader in = new BufferedReader (new InputStreamReader
(uc.getInputStream ()));
String inputLine;
for (inputLine = in.readLine();
inputLine != null;
inputLine = in.readLine())
{
result.add (inputLine);
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace ();
}
return result;
}
}
|