Skip to content

Instantly share code, notes, and snippets.

@eldetulado
Created September 30, 2021 22:37
Show Gist options
  • Save eldetulado/9e79ffed1831c1003300a5bfbf2304ef to your computer and use it in GitHub Desktop.
Save eldetulado/9e79ffed1831c1003300a5bfbf2304ef to your computer and use it in GitHub Desktop.
private fun convertStreamToString(inputStream: InputStream): String {
val reader = BufferedReader(InputStreamReader(inputStream, "utf-8"))
val sb = StringBuilder()
var line: String?
try {
while (reader.readLine().also { line = it } != null) {
sb.append(line)
}
} catch (e: Exception) {
e.printStackTrace()
} finally {
inputStream.close()
}
return sb.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment