Fix transfer failed msg
This commit is contained in:
1 parent
145d5e6302
commit
61fd8dc778
1 file changed
+3
-1
@@ -4,11 +4,13 @@ import okhttp3.ResponseBody
|
||||
import java.io.File
|
||||
|
||||
fun ResponseBody.copyToFile(file: File) {
|
||||
val length = contentLength()
|
||||
check(length > 0) { "contentLength < 0!" }
|
||||
val os = file.outputStream()
|
||||
val channel = os.channel
|
||||
val source = source()
|
||||
try {
|
||||
channel.transferFrom(source, 0, contentLength())
|
||||
channel.transferFrom(source, 0, length)
|
||||
} catch (e: Throwable) {
|
||||
throw e
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user