Skip to content

Instantly share code, notes, and snippets.

@kgilmer
Created August 22, 2018 00:52
Show Gist options
  • Save kgilmer/bf83a91e8af279fca326d5cad68e5186 to your computer and use it in GitHub Desktop.
Save kgilmer/bf83a91e8af279fca326d5cad68e5186 to your computer and use it in GitHub Desktop.
uamp read network in Java
BufferedReader reader = null;
try {
URLConnection urlConnection = new URL(urlString).openConnection();
reader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(), "iso-8859-1"));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return new JSONObject(sb.toString());
} catch (JSONException e) {
throw e;
} catch (Exception e) {
LogHelper.e(TAG, "Failed to parse the json for media list", e);
return null;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment