Last active
August 12, 2022 11:00
-
-
Save SerggioC/4472b32a33ac13862dc6149a38ee8835 to your computer and use it in GitHub Desktop.
get String from InputStream
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
@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