-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUHttp.java
72 lines (60 loc) · 1.75 KB
/
UHttp.java
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
66
67
68
69
70
71
72
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.net.URL;
import urbi.UObject;
public class UHttp extends UObject // must extends UObject
{
/// Register the class within urbi
static { UStart(UHttp.class); }
/// the class must have a single constructor taking a string
public UHttp (String s)
{
super (s);
/// Bind the function to Urbi
UBindFunction ("init");
}
/// The init function is the constructor in Urbi.
public int init ()
{
/// Bind the function add to Urbi
UBindFunction ("get");
// success
return 0;
}
/// Our method.
public String get(String url)
{
/*
UHttp.java:37: unreported exception java.net.MalformedURLException; must be caught or declared to be thrown
URL u = new URL(url);
^
UHttp.java:38: unreported exception java.io.IOException; must be caught or declared to be thrown
BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
^
UHttp.java:43: unreported exception java.io.IOException; must be caught or declared to be thrown
while ((inputLine = in.readLine()) != null)
^
UHttp.java:46: unreported exception java.io.IOException; must be caught or declared to be thrown
in.close();
^
*/
try
{
URL u = new URL(url);
BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
String inputLine;
StringBuilder sb = new StringBuilder();
while ((inputLine = in.readLine()) != null)
sb.append(inputLine);
in.close();
inputLine = sb.toString();
sb = null;
return inputLine;
} catch (Exception e) {
for( StackTraceElement ste : e.getStackTrace() ) {
System.out.println( ste + "\n" );
}
return "Exception caught : " + e ;
}
}
}