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);
  }
 

Implementation is not thread-safe.

Since:
1.1
Author:
Yaniv Inbar

Field Summary
 String boundary
          Deprecated. (scheduled to be made private in 1.6) Use getBoundary() or setBoundary(java.lang.String)
 Collection<HttpContent> parts
          Deprecated. (scheduled to be made private final in 1.6) Use getParts()
 
Constructor Summary
MultipartRelatedContent()
          Deprecated. (scheduled to be made private in 1.6) Use MultipartRelatedContent(HttpContent, HttpContent...) and forRequest(HttpRequest)
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".
static MultipartRelatedContent forRequest(HttpRequest request, HttpContent... parts)
          Deprecated. (scheduled to be made private in 1.6) Use MultipartRelatedContent(HttpContent, HttpContent...) and forRequest(HttpRequest)
 String getBoundary()
          Returns the boundary string to use.
 Collection<HttpContent> getParts()
          Returns the HTTP content parts.
 String getType()
          Returns the content type or null for none.
 boolean retrySupported()
          Default implementation returns true, but subclasses may override.
 MultipartRelatedContent setBoundary(String boundary)
          Sets the boundary string to use.
 void writeTo(OutputStream out)
          Writes the content to the given output stream.
 
Methods inherited from class com.google.api.client.http.AbstractHttpContent
getEncoding, getLength
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

boundary

@Deprecated
public String boundary
Deprecated. (scheduled to be made private in 1.6) Use getBoundary() or setBoundary(java.lang.String)
Boundary string to use. By default, it is "END_OF_PART".


parts

@Deprecated
public Collection<HttpContent> parts
Deprecated. (scheduled to be made private final in 1.6) Use getParts()
Collection of HTTP content parts.

By default, it is an empty list.

Constructor Detail

MultipartRelatedContent

@Deprecated
public MultipartRelatedContent()
Deprecated. (scheduled to be made private in 1.6) Use MultipartRelatedContent(HttpContent, HttpContent...) and forRequest(HttpRequest)


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

forRequest

@Deprecated
public static MultipartRelatedContent forRequest(HttpRequest request,
                                                            HttpContent... parts)
Deprecated. (scheduled to be made private in 1.6) Use MultipartRelatedContent(HttpContent, HttpContent...) and forRequest(HttpRequest)

Returns a new multi-part content serializer as the content for the given HTTP request.

It also sets the MIME version of headers to "1.0".

Parameters:
request - HTTP request
parts - HTTP content parts
Returns:
new multi-part content serializer

writeTo

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

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

getType

public String getType()
Description copied from interface: HttpContent
Returns the content type or null for none.


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

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 Google. All Rights Reserved.