Merge pull request #414 from Dominaezzz/kt-leak

Fix potential resource leak
This commit is contained in:
Benoit Marty 2019-08-06 11:39:51 +02:00 committed by GitHub
commit c2e053b62b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,11 +26,8 @@ import java.io.InputStream
*/
@WorkerThread
fun writeToFile(inputStream: InputStream, outputFile: File) {
val source = Okio.buffer(Okio.source(inputStream))
val sink = Okio.buffer(Okio.sink(outputFile))

source.use { input ->
sink.use { output ->
Okio.buffer(Okio.source(inputStream)).use { input ->
Okio.buffer(Okio.sink(outputFile)).use { output ->
output.writeAll(input)
}
}