public class MultipartContent extends AbstractHttpContent
By default the media type is "multipart/related; boundary=__END_OF_PART__<random
UUID>__"
, but this may be customized by calling setMediaType(HttpMediaType)
, AbstractHttpContent.getMediaType()
, or setBoundary(String)
.
Implementation is not thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
MultipartContent.Part
Single part of a multi-part request.
|
Constructor and Description |
---|
MultipartContent() |
MultipartContent(String boundary) |
Modifier and Type | Method and Description |
---|---|
MultipartContent |
addPart(MultipartContent.Part part)
Adds an HTTP multipart part.
|
String |
getBoundary()
Returns the boundary string to use.
|
Collection<MultipartContent.Part> |
getParts()
Returns an unmodifiable view of the parts of the HTTP multipart request.
|
boolean |
retrySupported()
Default implementation returns
true , but subclasses may override. |
MultipartContent |
setBoundary(String boundary)
Sets the boundary string to use.
|
MultipartContent |
setContentParts(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, or
null if unspecified. |
MultipartContent |
setParts(Collection<MultipartContent.Part> parts)
Sets the parts of the HTTP multipart request.
|
void |
writeTo(OutputStream out)
Writes the byte content to the given output stream.
|
computeLength, computeLength, getCharset, getLength, getMediaType, getType
public MultipartContent()
public MultipartContent(String boundary)
public void writeTo(OutputStream out) throws IOException
StreamingContent
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.
out
- output streamIOException
public boolean retrySupported()
AbstractHttpContent
true
, but subclasses may override.retrySupported
in interface HttpContent
retrySupported
in class AbstractHttpContent
public MultipartContent setMediaType(HttpMediaType mediaType)
AbstractHttpContent
null
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 AbstractHttpContent
public final Collection<MultipartContent.Part> getParts()
public MultipartContent addPart(MultipartContent.Part part)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public MultipartContent setParts(Collection<MultipartContent.Part> parts)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public MultipartContent setContentParts(Collection<? extends HttpContent> contentParts)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public final String getBoundary()
public MultipartContent setBoundary(String boundary)
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.
Copyright © 2011–2023 Google. All rights reserved.