Advertisement
Guest User

Untitled

a guest
Dec 4th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. public class Main {
  2.  
  3.   private static String readAll(Reader rd) throws IOException {
  4.     StringBuilder sb = new StringBuilder();
  5.     int cp;
  6.     while ((cp = rd.read()) != -1) {
  7.       sb.append((char) cp);
  8.     }
  9.     return sb.toString();
  10.   }
  11.  
  12.   public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
  13.     InputStream is = new URL(url).openStream();
  14.     try {
  15.       BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
  16.       String jsonText = readAll(rd);
  17.       JSONObject json = new JSONObject(jsonText);
  18.       return json;
  19.     } finally {
  20.       is.close();
  21.     }
  22.   }
  23.  
  24.   public static void main(String[] args) throws IOException, JSONException {
  25.       JSONObject json = readJsonFromUrl("http://status.mojang.com/check");
  26.       System.out.println(json.toString());
  27.       System.out.println(json.get("minecraft.net"));
  28.    
  29.       System.out.println(json.toString());
  30.       System.out.println(json.get("login.minecraft.net"));
  31.    
  32.       System.out.println(json.toString());
  33.       System.out.println(json.get("session.minecraft.net"));
  34.    
  35.       System.out.println(json.toString());
  36.       System.out.println(json.get("account.mojang.com"));
  37.    
  38.       System.out.println(json.toString());
  39.       System.out.println(json.get("auth.mojang.com"));
  40.    
  41.       System.out.println(json.toString());
  42.       System.out.println(json.get("skins.minecraft.com"));
  43.  
  44.    
  45.   }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement