Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. package ecs161.querying.util;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.URL;
  7.  
  8. import org.json.JSONObject;
  9.  
  10. public class Util {
  11.  
  12. public static JSONObject queryURL(URL url) throws IOException {
  13. // Read all bytes from the URL, if it exists. If it does not, the code below will throw an IOException
  14. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  15. StringBuilder sb = new StringBuilder();
  16. int cp;
  17. while ((cp = in.read()) != -1) {
  18. sb.append((char) cp);
  19. }
  20. in.close();
  21. String content = sb.toString();
  22. // Extract issue-type from the JSON object returned.
  23. String jsonText = "{root:" + content + "}";
  24. JSONObject json = new JSONObject(jsonText);
  25. return json;
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement