Class ProtoHttpContent (1.41.8)

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.

Inheritance

java.lang.Object > AbstractHttpContent > ProtoHttpContent

Constructors

ProtoHttpContent(MessageLite message)

public ProtoHttpContent(MessageLite message)
Parameter
NameDescription
messageMessageLite

message to serialize

Methods

getLength()

public long getLength()

Default implementation calls #computeLength() once and caches it for future invocations, but subclasses may override.

Returns
TypeDescription
long
Overrides Exceptions
TypeDescription
IOException

getMessage()

public final MessageLite getMessage()

Returns the message to serialize.

Returns
TypeDescription
MessageLite

setMediaType(HttpMediaType mediaType)

public ProtoHttpContent setMediaType(HttpMediaType mediaType)

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.

Parameter
NameDescription
mediaTypeHttpMediaType
Returns
TypeDescription
ProtoHttpContent
Overrides

writeTo(OutputStream out)

public void writeTo(OutputStream out)
Parameter
NameDescription
outOutputStream
Exceptions
TypeDescription
IOException