Created
September 1, 2022 04:47
-
-
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
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
/** | |
* 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