Skip to content

Instantly share code, notes, and snippets.

@JuniiiSays
Created September 1, 2022 04:47
Show Gist options
  • Save JuniiiSays/2b1aa864394c53f2ba63449a19780fe7 to your computer and use it in GitHub Desktop.
Save JuniiiSays/2b1aa864394c53f2ba63449a19780fe7 to your computer and use it in GitHub Desktop.
This method will get a InputStream as input and return a String of response
/**
* Convert the {@link InputStream} into a String which contains the
* whole JSON response from the server.
*/
private static String readFromStream(InputStream inputStream) throws IOException {
StringBuilder output = new StringBuilder();
if (inputStream != null){
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
BufferedReader reader = new BufferedReader(inputStreamReader);
String line = reader.readLine();
while (line != null){
output.append(line);
line = reader.readLine();
}
}
return output.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment