com.google.api.client.http
Class MultipartRelatedContent

java.lang.Object
  extended by com.google.api.client.http.AbstractHttpContent
      extended by com.google.api.client.http.MultipartRelatedContent
All Implemented Interfaces:
HttpContent

public final class MultipartRelatedContent
extends AbstractHttpContent

Serializes MIME Multipart/Related content as specified by RFC 2387: The MIME Multipart/Related Content-type.

Limitations:

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.

Since:
1.1
Author:
Yaniv Inbar

Constructor Summary
MultipartRelatedContent(HttpContent firstPart, HttpContent... otherParts)
           
 
Method Summary
 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.
 
Methods inherited from class com.google.api.client.http.AbstractHttpContent
getCharset, getEncoding, getLength, getMediaType, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartRelatedContent

public MultipartRelatedContent(HttpContent firstPart,
                               HttpContent... otherParts)
Parameters:
firstPart - first HTTP content part
otherParts - other HTTP content parts
Since:
1.5
Method Detail

forRequest

public 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".

Parameters:
request - HTTP request
Since:
1.5

writeTo

public void writeTo(OutputStream out)
             throws IOException
Description copied from interface: HttpContent
Writes the content to the given output stream.

The 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.

Throws:
IOException

computeLength

public long computeLength()
                   throws IOException
Description copied from class: AbstractHttpContent
Computes and returns the content length or less than zero if not known.

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.

Overrides:
computeLength in class AbstractHttpContent
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 MultipartRelatedContent 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

getBoundary

public String getBoundary()
Returns the boundary string to use.

Since:
1.5

setBoundary

public MultipartRelatedContent setBoundary(String boundary)
Sets the boundary string to use.

Defaults to "END_OF_PART".

Since:
1.5

getParts

public Collection<HttpContent> getParts()
Returns the HTTP content parts.

Since:
1.5


Copyright © 2011-2012 Google. All Rights Reserved.