com.google.api.client.http.protobuf
Class ProtoHttpContent

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

public class ProtoHttpContent
extends AbstractHttpContent

Serializes of a protocol buffer message to HTTP content.

Sample usage:

 
  static HttpRequest buildPostRequest(
      HttpRequestFactory requestFactory, GenericUrl url, MessageLite message) throws IOException {
    return requestFactory.buildPostRequest(url, new ProtoHttpContent(message));
  }
 
 

Implementation is not thread-safe.

Since:
1.5
Author:
Yaniv Inbar

Constructor Summary
ProtoHttpContent(com.google.protobuf.MessageLite message)
           
 
Method Summary
 long getLength()
          Default implementation calls AbstractHttpContent.computeLength() once and caches it for future invocations, but subclasses may override.
 com.google.protobuf.MessageLite getMessage()
          Returns the message to serialize.
 String getType()
          Returns the content type or null for none.
 ProtoHttpContent setType(String type)
          Sets the content type or null for none.
 void writeTo(OutputStream out)
          Writes the content to the given output stream.
 
Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, getEncoding, retrySupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProtoHttpContent

public ProtoHttpContent(com.google.protobuf.MessageLite message)
Parameters:
message - message to serialize
Method Detail

getLength

public long getLength()
               throws IOException
Description copied from class: AbstractHttpContent
Default implementation calls AbstractHttpContent.computeLength() once and caches it for future invocations, but subclasses may override.

Specified by:
getLength in interface HttpContent
Overrides:
getLength in class AbstractHttpContent
Throws:
IOException

getType

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


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

setType

public ProtoHttpContent setType(String type)
Sets the content type or null for none.

Default value is ProtocolBuffers.CONTENT_TYPE.


getMessage

public final com.google.protobuf.MessageLite getMessage()
Returns the message to serialize.



Copyright © 2011-2012 Google. All Rights Reserved.