Skip to content

Instantly share code, notes, and snippets.

@SerggioC
Last active August 12, 2022 11:00
Show Gist options
  • Save SerggioC/4472b32a33ac13862dc6149a38ee8835 to your computer and use it in GitHub Desktop.
Save SerggioC/4472b32a33ac13862dc6149a38ee8835 to your computer and use it in GitHub Desktop.
get String from InputStream
@Throws(java.lang.Exception::class)
fun convertStreamToString(input: InputStream?): String? {
input ?: return null
val reader = BufferedReader(InputStreamReader(input))
val sb = StringBuilder()
var line: String?
while (reader.readLine().also { line = it } != null) {
sb.append(line).append("\n")
}
reader.close()
return sb.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment