Class ProtoHttpContent

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

@Beta public class ProtoHttpContent extends AbstractHttpContent
Beta
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
  • Field Details

    • message

      private final com.google.protobuf.MessageLite message
      Message to serialize.
  • Constructor Details

    • ProtoHttpContent

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

    • 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
    • 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 output stream has not been closed, and will fail to work if it has been closed.

      Parameters:
      out - output stream
      Throws:
      IOException
    • getMessage

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

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