Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Main {
- private static final String TOKEN = "\"Authorization: procon30_example_token\"";
- private static final String ADDRESS = "http://localhost:3000/";
- public static void main(String[] args) throws IOException {
- }
- public static String getMatches() throws IOException {
- String command = "curl -H " + TOKEN + " " + ADDRESS + "matches";
- ProcessBuilder pb = new ProcessBuilder(command.split(" "));
- Process process = pb.start();
- InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
- StringBuilder sb = new StringBuilder();
- for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
- sb.append((char)input);
- }
- process.destroy();
- return sb.toString();
- }
- public static String getMatch(int id) throws IOException {
- String command = "curl -H " + TOKEN + " " + ADDRESS + "matches/" + id;
- ProcessBuilder pb = new ProcessBuilder(command.split(" "));
- Process process = pb.start();
- InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
- StringBuilder sb = new StringBuilder();
- for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
- sb.append((char)input);
- }
- process.destroy();
- return sb.toString();
- }
- public static String postAction(int id, String json) throws IOException {
- String command = "curl -H " + TOKEN + " " + "-H \"Content-Type: application/json\" -X POST "+ ADDRESS + "matches/" + id + "/action -d\"" + json.replace("\"", "\\\"") + "\"";
- ProcessBuilder pb = new ProcessBuilder(command.split(" "));
- Process process = pb.start();
- InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
- StringBuilder sb = new StringBuilder();
- for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
- sb.append((char)input);
- }
- process.destroy();
- return sb.toString();
- }
- public static boolean ping() throws IOException {
- String command = "curl -H " + TOKEN + " " + ADDRESS + "ping";
- ProcessBuilder pb = new ProcessBuilder(command.split(" "));
- Process process = pb.start();
- InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
- StringBuilder sb = new StringBuilder();
- for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
- sb.append((char)input);
- }
- process.destroy();
- return sb.toString().contains("OK");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement