public final class MultipartRelatedContent extends AbstractHttpContent
Limitations:
"boundary"HttpContent.getType() must not be
null
Use forRequest(HttpRequest) to construct. For example:
static void setMediaWithMetadataContent(
HttpRequest request, AtomContent atomContent, InputStreamContent imageContent) {
MultipartRelatedContent.forRequest(request, atomContent, imageContent);
}
writeTo(java.io.OutputStream) can be called multiple times for Multipart/Related content. Parts must not
close the output stream in writeTo(java.io.OutputStream).
Implementation is not thread-safe.
| Constructor and Description |
|---|
MultipartRelatedContent(HttpContent firstPart,
HttpContent... otherParts) |
| Modifier and Type | Method and Description |
|---|---|
long |
computeLength()
Computes and returns the content length or less than zero if not known.
|
void |
forRequest(HttpRequest request)
Sets this multi-part content as the content for the given HTTP request, and set the
MIME version header to "1.0". |
String |
getBoundary()
Returns the boundary string to use.
|
Collection<HttpContent> |
getParts()
Returns the HTTP content parts.
|
boolean |
retrySupported()
Default implementation returns
true, but subclasses may override. |
MultipartRelatedContent |
setBoundary(String boundary)
Sets the boundary string to use.
|
MultipartRelatedContent |
setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, or
null if unspecified. |
void |
writeTo(OutputStream out)
Writes the content to the given output stream.
|
getCharset, getEncoding, getLength, getMediaType, getTypepublic MultipartRelatedContent(HttpContent firstPart, HttpContent... otherParts)
firstPart - first HTTP content partotherParts - other HTTP content partspublic void forRequest(HttpRequest request)
MIME version header to "1.0".request - HTTP requestpublic void writeTo(OutputStream out) throws IOException
HttpContentThe recommendation for implementations is that they should not close the output stream. Callers should not assume whether or not the output stream has been closed. Implementations that do not close the output stream should flush it at the end of the method.
IOExceptionpublic long computeLength()
throws IOException
AbstractHttpContent
Subclasses may override, but by default this computes the length by calling
HttpContent.writeTo(OutputStream) with an output stream that does not process the bytes written,
but only retains the count of bytes. If AbstractHttpContent.retrySupported() is false, it will
instead return -1.
computeLength in class AbstractHttpContentIOExceptionpublic boolean retrySupported()
AbstractHttpContenttrue, but subclasses may override.retrySupported in interface HttpContentretrySupported in class AbstractHttpContentpublic MultipartRelatedContent setMediaType(HttpMediaType mediaType)
AbstractHttpContentnull if unspecified.
This will also overwrite any previously set parameter of the media type (for example
"charset"), and therefore might change other properties as well.
setMediaType in class AbstractHttpContentpublic String getBoundary()
public MultipartRelatedContent setBoundary(String boundary)
Defaults to "END_OF_PART".
public Collection<HttpContent> getParts()
Copyright © 2011-2012 Google. All Rights Reserved.