Skip to content

Commit

Permalink
Refactor input and output stream when copying files locally
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Oct 23, 2024
1 parent 8103d15 commit ae4af87
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,17 @@ class UploadLocalStorage @Inject constructor(@ApplicationContext private val app
runCatching { createNewFile() }.onFailure { return null }

runCatching {
val inputStream = appContext.contentResolver.openInputStream(uri) ?: run {
appContext.contentResolver.openInputStream(uri)?.use { inputStream ->
outputStream().use { outputStream ->
inputStream.copyTo(outputStream)
}
} ?: run {
Sentry.withScope { scope ->
scope.level = SentryLevel.ERROR
Sentry.addBreadcrumb("During local copy of the file openInputStream returned null")
}
return null
}

inputStream.use { inputStream ->
outputStream().use { outputStream ->
inputStream.copyTo(outputStream)
}
}
}.onFailure {
Sentry.withScope { scope ->
scope.level = SentryLevel.ERROR
Expand Down

0 comments on commit ae4af87

Please sign in to comment.