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 calling setMediaType(HttpMediaType), AbstractHttpContent.getMediaType(), or setBoundary(String).

Implementation is not thread-safe.

Since:
1.14
  • Field Details

  • Constructor Details

    • MultipartContent

      public MultipartContent()
  • Method Details

    • writeTo

      public void writeTo(OutputStream out) throws 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:
      IOException
    • retrySupported

      public boolean retrySupported()
      Description copied from class: AbstractHttpContent
      Default implementation returns true, but subclasses may override.
      Specified by:
      retrySupported in interface HttpContent
      Overrides:
      retrySupported in class AbstractHttpContent
    • setMediaType

      public MultipartContent setMediaType(HttpMediaType mediaType)
      Description copied from class: AbstractHttpContent
      Sets the media type to use for the Content-Type header, or 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.

      Overrides:
      setMediaType in class AbstractHttpContent
    • getParts

      public final 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

      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(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 String getBoundary()
      Returns the boundary string to use.
    • setBoundary

      public MultipartContent setBoundary(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.