Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.InputStreamReader;
  3.  
  4. public class Main {
  5.  
  6. private static final String TOKEN = "\"Authorization: procon30_example_token\"";
  7. private static final String ADDRESS = "http://localhost:3000/";
  8.  
  9. public static void main(String[] args) throws IOException {
  10.  
  11. }
  12.  
  13. public static String getMatches() throws IOException {
  14. String command = "curl -H " + TOKEN + " " + ADDRESS + "matches";
  15. ProcessBuilder pb = new ProcessBuilder(command.split(" "));
  16. Process process = pb.start();
  17. InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
  18. StringBuilder sb = new StringBuilder();
  19. for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
  20. sb.append((char)input);
  21. }
  22. process.destroy();
  23. return sb.toString();
  24. }
  25.  
  26. public static String getMatch(int id) throws IOException {
  27. String command = "curl -H " + TOKEN + " " + ADDRESS + "matches/" + id;
  28. ProcessBuilder pb = new ProcessBuilder(command.split(" "));
  29. Process process = pb.start();
  30. InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
  31. StringBuilder sb = new StringBuilder();
  32. for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
  33. sb.append((char)input);
  34. }
  35. process.destroy();
  36. return sb.toString();
  37. }
  38.  
  39. public static String postAction(int id, String json) throws IOException {
  40. String command = "curl -H " + TOKEN + " " + "-H \"Content-Type: application/json\" -X POST "+ ADDRESS + "matches/" + id + "/action -d\"" + json.replace("\"", "\\\"") + "\"";
  41. ProcessBuilder pb = new ProcessBuilder(command.split(" "));
  42. Process process = pb.start();
  43. InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
  44. StringBuilder sb = new StringBuilder();
  45. for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
  46. sb.append((char)input);
  47. }
  48. process.destroy();
  49. return sb.toString();
  50. }
  51.  
  52. public static boolean ping() throws IOException {
  53. String command = "curl -H " + TOKEN + " " + ADDRESS + "ping";
  54. ProcessBuilder pb = new ProcessBuilder(command.split(" "));
  55. Process process = pb.start();
  56. InputStreamReader inputStream = new InputStreamReader(process.getInputStream());
  57. StringBuilder sb = new StringBuilder();
  58. for(int input = inputStream.read(); input != -1; input = inputStream.read()) {
  59. sb.append((char)input);
  60. }
  61. process.destroy();
  62. return sb.toString().contains("OK");
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement