aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/utility/WebAPI.java
blob: 86b7312cb69eae8d6cda10a9db671cd6646f3a02 (plain) (blame)
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
package utility;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class WebAPI {
    public String[] getURLsFromSite(String urlString) {
        try {
            System.out.println("Getting URLs from " + urlString);
            try (InputStream is = new URL(urlString).openStream();
                 BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
                StringBuilder sb = new StringBuilder();
                int cb;
                while ((cb = br.read()) != -1) {
                    sb.append((char) cb);
                }
                return sb.toString().split("\n");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        catch (Exception e){
            System.out.println("Error: " + e.getMessage());
            return null;
        }
    }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage