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__"
, 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 class
MultipartContent.Part
Single part of a multi-part request.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
NEWLINE
private java.util.ArrayList<MultipartContent.Part>
parts
Parts of the HTTP multipart request.private static java.lang.String
TWO_DASHES
-
Constructor Summary
Constructors Constructor Description MultipartContent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultipartContent
addPart(MultipartContent.Part part)
Adds an HTTP multipart part.java.lang.String
getBoundary()
Returns the boundary string to use.java.util.Collection<MultipartContent.Part>
getParts()
Returns an unmodifiable view of the parts of the HTTP multipart request.boolean
retrySupported()
Default implementation returnstrue
, but subclasses may override.MultipartContent
setBoundary(java.lang.String boundary)
Sets the boundary string to use.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.MultipartContent
setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, ornull
if unspecified.MultipartContent
setParts(java.util.Collection<MultipartContent.Part> parts)
Sets the parts of the HTTP multipart request.void
writeTo(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.IOException
Description copied from interface:StreamingContent
Writes 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 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:AbstractHttpContent
Default implementation returnstrue
, but subclasses may override.- Specified by:
retrySupported
in interfaceHttpContent
- Overrides:
retrySupported
in classAbstractHttpContent
-
setMediaType
public MultipartContent setMediaType(HttpMediaType mediaType)
Description copied from class:AbstractHttpContent
Sets the media type to use for the Content-Type header, ornull
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.- Overrides:
setMediaType
in 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.
-
-