mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 22:29:09 +00:00
move streams to utilize "use"
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
58436286c7
commit
5a2b04740b
@ -1543,19 +1543,16 @@ class ChatController(args: Bundle) :
|
||||
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey)
|
||||
|
||||
val fd: AssetFileDescriptor = activity?.contentResolver!!.openAssetFileDescriptor(uri, "r")!!
|
||||
val fis = fd.createInputStream()
|
||||
fd.use {
|
||||
val fis = fd.createInputStream()
|
||||
|
||||
file.createNewFile()
|
||||
fis.use { input ->
|
||||
file.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
file.createNewFile()
|
||||
fis.use { input ->
|
||||
file.outputStream().use { output ->
|
||||
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) {
|
||||
|
@ -54,11 +54,12 @@ class FileUploader(
|
||||
var requestBody: RequestBody? = null
|
||||
try {
|
||||
val input: InputStream = context.contentResolver.openInputStream(sourceFileUri)!!
|
||||
val buf = ByteArray(input.available())
|
||||
while (input.read(buf) != -1) {
|
||||
requestBody = RequestBody.create("application/octet-stream".toMediaTypeOrNull(), buf)
|
||||
input.use {
|
||||
val buf = ByteArray(input.available())
|
||||
while (it.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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user