Class MultipartContent
- java.lang.Object
-
- com.google.api.client.http.AbstractHttpContent
-
- com.google.api.client.http.MultipartContent
-
- All Implemented Interfaces:
HttpContent,StreamingContent
public class MultipartContent extends AbstractHttpContent
Serializes MIME multipart content as specified by RFC 2387: The MIME Multipart/Related Content-type and RFC 2046: Multipurpose Internet Mail Extensions: The Multipart/mixed (primary) subtype.By default the media type is
"multipart/related; boundary=__END_OF_PART__<random UUID>__", but this may be customized by callingsetMediaType(HttpMediaType),AbstractHttpContent.getMediaType(), orsetBoundary(String).Implementation is not thread-safe.
- Since:
- 1.14
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMultipartContent.PartSingle part of a multi-part request.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringNEWLINEprivate java.util.ArrayList<MultipartContent.Part>partsParts of the HTTP multipart request.private static java.lang.StringTWO_DASHES
-
Constructor Summary
Constructors Constructor Description MultipartContent()MultipartContent(java.lang.String boundary)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultipartContentaddPart(MultipartContent.Part part)Adds an HTTP multipart part.java.lang.StringgetBoundary()Returns the boundary string to use.java.util.Collection<MultipartContent.Part>getParts()Returns an unmodifiable view of the parts of the HTTP multipart request.booleanretrySupported()Default implementation returnstrue, but subclasses may override.MultipartContentsetBoundary(java.lang.String boundary)Sets the boundary string to use.MultipartContentsetContentParts(java.util.Collection<? extends HttpContent> contentParts)Sets the HTTP content parts of the HTTP multipart request, where each part is assumed to have no HTTP headers and no encoding.MultipartContentsetMediaType(HttpMediaType mediaType)Sets the media type to use for the Content-Type header, ornullif unspecified.MultipartContentsetParts(java.util.Collection<MultipartContent.Part> parts)Sets the parts of the HTTP multipart request.voidwriteTo(java.io.OutputStream out)Writes the byte content to the given output stream.-
Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, computeLength, getCharset, getLength, getMediaType, getType
-
-
-
-
Field Detail
-
NEWLINE
static final java.lang.String NEWLINE
- See Also:
- Constant Field Values
-
TWO_DASHES
private static final java.lang.String TWO_DASHES
- See Also:
- Constant Field Values
-
parts
private java.util.ArrayList<MultipartContent.Part> parts
Parts of the HTTP multipart request.
-
-
Method Detail
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionDescription copied from interface:StreamingContentWrites the byte content to the given output stream.Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the output stream has not been closed, and will fail to work if it has been closed.
- Parameters:
out- output stream- Throws:
java.io.IOException
-
retrySupported
public boolean retrySupported()
Description copied from class:AbstractHttpContentDefault implementation returnstrue, but subclasses may override.- Specified by:
retrySupportedin interfaceHttpContent- Overrides:
retrySupportedin classAbstractHttpContent
-
setMediaType
public MultipartContent setMediaType(HttpMediaType mediaType)
Description copied from class:AbstractHttpContentSets the media type to use for the Content-Type header, ornullif unspecified.This will also overwrite any previously set parameter of the media type (for example
"charset"), and therefore might change other properties as well.- Overrides:
setMediaTypein classAbstractHttpContent
-
getParts
public final java.util.Collection<MultipartContent.Part> getParts()
Returns an unmodifiable view of the parts of the HTTP multipart request.
-
addPart
public MultipartContent addPart(MultipartContent.Part part)
Adds an HTTP multipart part.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
setParts
public MultipartContent setParts(java.util.Collection<MultipartContent.Part> parts)
Sets the parts of the HTTP multipart request.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
setContentParts
public MultipartContent setContentParts(java.util.Collection<? extends HttpContent> contentParts)
Sets the HTTP content parts of the HTTP multipart request, where each part is assumed to have no HTTP headers and no encoding.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
getBoundary
public final java.lang.String getBoundary()
Returns the boundary string to use.
-
setBoundary
public MultipartContent setBoundary(java.lang.String boundary)
Sets the boundary string to use.Defaults to
"END_OF_PART".Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
-
-