Created
August 22, 2018 00:52
-
-
Save kgilmer/bf83a91e8af279fca326d5cad68e5186 to your computer and use it in GitHub Desktop.
uamp read network in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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