Class 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 Detail

      • message

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

      • ProtoHttpContent

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

      • writeTo

        public void writeTo​(java.io.OutputStream out)
                     throws java.io.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:
        java.io.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