Back to project page android-animeinfo.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project android-animeinfo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.winterday.android.Anime.Util; //from w w w. j ava2 s .c o m import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import org.json.JSONException; import org.json.JSONObject; import android.graphics.drawable.Drawable; public class JSONFetcher { public static JSONObject downloadJSON(String urlString) throws JSONException, IOException { String s = downloadString(urlString); if (s.startsWith("[")) return new JSONObject("{\"results\":" + s + "}"); else return new JSONObject(s); } public static Drawable downloadImage(String url) throws MalformedURLException, IOException { return Drawable.createFromStream(new URL(url).openStream(), "image"); } private static String downloadString(String urlString) throws IOException { BufferedReader reader = null; StringBuffer buffer = new StringBuffer(); URL url = new URL(urlString); reader = new BufferedReader(new InputStreamReader(url.openStream())); while (reader.ready()) buffer.append(reader.readLine()); reader.close(); return buffer.toString(); } }