MultipartReader

class MultipartReader constructor(source: BufferedSource, val boundary: String) : Closeable

Reads a stream of RFC 2046 multipart body parts. Callers read parts one-at-a-time until nextPart returns null. After calling nextPart any preceding parts should not be read.

Typical use loops over the parts in sequence:

val response: Response = call.execute()
val multipartReader = MultipartReader(response.body!!)

multipartReader.use {
while (true) {
val part = multipartReader.nextPart() ?: break
process(part.headers, part.body)
}
}

Note that nextPart will skip any unprocessed data from the preceding part. If the preceding part is particularly large or if the underlying source is particularly slow, the nextPart call may be slow!

Closing a part does not close this multipart reader; callers must explicitly close this with close.

Constructors

Link copied to clipboard
constructor(response: ResponseBody)
constructor(source: BufferedSource, boundary: String)

Types

Link copied to clipboard
class Part(val headers: Headers, val body: BufferedSource) : Closeable

A single part in a multipart body.

Properties

Link copied to clipboard
@get:JvmName(name = "boundary")
val boundary: String

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard