Cleanup code
filechannel is close when ios closed
This commit is contained in:
1 parent
47da1bcdb4
commit
3ea0b0847a
2 files changed
+6
-15
No files matched your search
@@ -187,10 +187,8 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) {
|
||||
|
||||
suspend fun doSave(outFile: UniFile): Long {
|
||||
val ret: Long
|
||||
outFile.openOutputStream().use { outputStream ->
|
||||
outputStream.channel.use {
|
||||
ret = body.bodyAsChannel().copyTo(it)
|
||||
}
|
||||
outFile.openOutputStream().use {
|
||||
ret = body.bodyAsChannel().copyTo(it.channel)
|
||||
}
|
||||
if (contentType == ContentType.Image.GIF)
|
||||
outFile.openFileDescriptor("rw").use {
|
||||
|
||||
@@ -4,16 +4,9 @@ import okhttp3.ResponseBody
|
||||
import java.io.File
|
||||
|
||||
fun ResponseBody.copyToFile(file: File) {
|
||||
val os = file.outputStream()
|
||||
val channel = os.channel
|
||||
val source = source()
|
||||
try {
|
||||
channel.transferFrom(source, 0, Long.MAX_VALUE)
|
||||
} catch (e: Throwable) {
|
||||
throw e
|
||||
} finally {
|
||||
source.close()
|
||||
channel.close()
|
||||
os.close()
|
||||
file.outputStream().use { os ->
|
||||
source().use {
|
||||
os.channel.transferFrom(it, 0, Long.MAX_VALUE)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user