public final class MultipartBody extends RequestBody
Modifier and Type | Class and Description |
---|---|
static class |
MultipartBody.Builder |
static class |
MultipartBody.Part |
Modifier and Type | Field and Description |
---|---|
static MediaType |
ALTERNATIVE
The "multipart/alternative" type is syntactically identical to "multipart/mixed", but the
semantics are different.
|
private okio.ByteString |
boundary |
private static byte[] |
COLONSPACE |
private long |
contentLength |
private MediaType |
contentType |
private static byte[] |
CRLF |
private static byte[] |
DASHDASH |
static MediaType |
DIGEST
This type is syntactically identical to "multipart/mixed", but the semantics are different.
|
static MediaType |
FORM
The media-type multipart/form-data follows the rules of all multipart MIME data streams as
outlined in RFC 2046.
|
static MediaType |
MIXED
The "mixed" subtype of "multipart" is intended for use when the body parts are independent and
need to be bundled in a particular order.
|
private MediaType |
originalType |
static MediaType |
PARALLEL
This type is syntactically identical to "multipart/mixed", but the semantics are different.
|
private java.util.List<MultipartBody.Part> |
parts |
Constructor and Description |
---|
MultipartBody(okio.ByteString boundary,
MediaType type,
java.util.List<MultipartBody.Part> parts) |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
appendQuotedString(java.lang.StringBuilder target,
java.lang.String key)
Appends a quoted-string to a StringBuilder.
|
java.lang.String |
boundary() |
long |
contentLength()
Returns the number of bytes that will be written to
sink in a call to RequestBody.writeTo(okio.BufferedSink) ,
or -1 if that count is unknown. |
MediaType |
contentType()
A combination of
type() and boundary() . |
MultipartBody.Part |
part(int index) |
java.util.List<MultipartBody.Part> |
parts() |
int |
size()
The number of parts in this multipart body.
|
MediaType |
type() |
private long |
writeOrCountBytes(okio.BufferedSink sink,
boolean countBytes)
Either writes this request to
sink or measures its content length. |
void |
writeTo(okio.BufferedSink sink)
Writes the content of this request to
sink . |
public static final MediaType MIXED
public static final MediaType ALTERNATIVE
public static final MediaType DIGEST
Content-Type
value for a body part is changed from
"text/plain" to "message/rfc822".public static final MediaType PARALLEL
public static final MediaType FORM
private static final byte[] COLONSPACE
private static final byte[] CRLF
private static final byte[] DASHDASH
private final okio.ByteString boundary
private final MediaType originalType
private final MediaType contentType
private final java.util.List<MultipartBody.Part> parts
private long contentLength
MultipartBody(okio.ByteString boundary, MediaType type, java.util.List<MultipartBody.Part> parts)
public MediaType type()
public java.lang.String boundary()
public int size()
public java.util.List<MultipartBody.Part> parts()
public MultipartBody.Part part(int index)
public MediaType contentType()
type()
and boundary()
.contentType
in class RequestBody
public long contentLength() throws java.io.IOException
RequestBody
sink
in a call to RequestBody.writeTo(okio.BufferedSink)
,
or -1 if that count is unknown.contentLength
in class RequestBody
java.io.IOException
public void writeTo(okio.BufferedSink sink) throws java.io.IOException
RequestBody
sink
.writeTo
in class RequestBody
java.io.IOException
private long writeOrCountBytes(@Nullable okio.BufferedSink sink, boolean countBytes) throws java.io.IOException
sink
or measures its content length. We have one method
do double-duty to make sure the counting and content are consistent, particularly when it comes
to awkward operations like measuring the encoded length of header strings, or the
length-in-digits of an encoded integer.java.io.IOException
static void appendQuotedString(java.lang.StringBuilder target, java.lang.String key)
RFC 2388 is rather vague about how one should escape special characters in form-data parameters, and as it turns out Firefox and Chrome actually do rather different things, and both say in their comments that they're not really sure what the right approach is. We go with Chrome's behavior (which also experimentally seems to match what IE does), but if you actually want to have a good chance of things working, please avoid double-quotes, newlines, percent signs, and the like in your field names.