close streams after use

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-09-16 13:35:10 +02:00
parent 5ac4dccda6
commit 8acb646383
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
2 changed files with 8 additions and 1 deletions

View File

@ -1551,6 +1551,11 @@ class ChatController(args: Bundle) :
input.copyTo(output)
}
}
try {
fd.close()
} catch (e: IOException) {
Log.w(TAG, "Failed to close AssetFileDescriptor", e)
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

View File

@ -55,8 +55,10 @@ class FileUploader(
try {
val input: InputStream = context.contentResolver.openInputStream(sourceFileUri)!!
val buf = ByteArray(input.available())
while (input.read(buf) != -1)
while (input.read(buf) != -1) {
requestBody = RequestBody.create("application/octet-stream".toMediaTypeOrNull(), buf)
}
input.close()
} catch (e: Exception) {
Log.e(TAG, "failed to create RequestBody for $sourceFileUri", e)
}