|
|
@ -7,13 +7,10 @@ import org.chromium.net.UploadDataSink |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
import java.nio.ByteBuffer |
|
|
|
import java.nio.ByteBuffer |
|
|
|
|
|
|
|
|
|
|
|
class BodyUploadProvider(body: RequestBody) : UploadDataProvider(), AutoCloseable { |
|
|
|
class BodyUploadProvider(private val body: RequestBody) : UploadDataProvider(), AutoCloseable { |
|
|
|
private val body: RequestBody |
|
|
|
private val buffer = Buffer() |
|
|
|
private val buffer: Buffer? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
buffer = Buffer() |
|
|
|
|
|
|
|
this.body = body |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
body.writeTo(buffer) |
|
|
|
body.writeTo(buffer) |
|
|
|
} catch (e: IOException) { |
|
|
|
} catch (e: IOException) { |
|
|
@ -32,7 +29,7 @@ class BodyUploadProvider(body: RequestBody) : UploadDataProvider(), AutoCloseabl |
|
|
|
var read: Int |
|
|
|
var read: Int |
|
|
|
var bytesRead = 0 |
|
|
|
var bytesRead = 0 |
|
|
|
while (bytesRead == 0) { |
|
|
|
while (bytesRead == 0) { |
|
|
|
read = buffer!!.read(byteBuffer) |
|
|
|
read = buffer.read(byteBuffer) |
|
|
|
bytesRead += read |
|
|
|
bytesRead += read |
|
|
|
} |
|
|
|
} |
|
|
|
uploadDataSink.onReadSucceeded(false) |
|
|
|
uploadDataSink.onReadSucceeded(false) |
|
|
@ -40,12 +37,14 @@ class BodyUploadProvider(body: RequestBody) : UploadDataProvider(), AutoCloseabl |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
@Throws(IOException::class) |
|
|
|
override fun rewind(uploadDataSink: UploadDataSink) { |
|
|
|
override fun rewind(uploadDataSink: UploadDataSink) { |
|
|
|
|
|
|
|
buffer.clear() |
|
|
|
|
|
|
|
body.writeTo(buffer) |
|
|
|
uploadDataSink.onRewindSucceeded() |
|
|
|
uploadDataSink.onRewindSucceeded() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
@Throws(IOException::class) |
|
|
|
override fun close() { |
|
|
|
override fun close() { |
|
|
|
buffer?.close() |
|
|
|
buffer.close() |
|
|
|
super.close() |
|
|
|
super.close() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |