-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenStram.java
More file actions
45 lines (32 loc) · 1.16 KB
/
Copy pathOpenStram.java
File metadata and controls
45 lines (32 loc) · 1.16 KB
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
package API;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;
public class OpenStram {
public static void main(String ar[]) throws Exception {
String url = "https://dh99qhj4ry.apigw.ntruss.com/vpc-api/stage/checkConnAwsDb";
JSONObject json = readJsonFromUrl(url);
System.out.println(json.toString());
}
private static String jsonReadAll(Reader reader) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = reader.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
private static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
InputStream is = new URL(url).openStream();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = jsonReadAll(br);
JSONObject json = new JSONObject(jsonText);
return json;
} finally {
is.close();
}
}
}