-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServer.java
More file actions
38 lines (34 loc) · 1.3 KB
/
Server.java
File metadata and controls
38 lines (34 loc) · 1.3 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
package com.yurii.salimov.lesson12.task02;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public abstract class Server {
public static int getStatus(final String link) throws IOException, InterruptedException {
String _link = link.replace("https://", "").replace("http://", "");
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("ping " + _link);
return process.waitFor();
}
public static void /*String*/ getPage(final String link) throws IOException {
//StringBuilder page = new StringBuilder();
final URL url = new URL(link);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try (InputStreamReader is = new InputStreamReader(connection.getInputStream());
BufferedReader br = new BufferedReader(is)) {
char[] buffer = new char[1024];
//int size;
while ((/*size = */br.read(buffer)) >= 0) {
//page.append(new String(buffer, 0, size));
}
} finally {
connection.disconnect();
}
//return page.toString();
}
}