Class ProtoHttpContent (1.45.0)

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
Name Description
message MessageLite

message to serialize

Methods

getLength()

public long getLength()

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

Returns
Type Description
long
Overrides
Exceptions
Type Description
IOException

getMessage()

public final MessageLite getMessage()

Returns the message to serialize.

Returns
Type Description
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
Name Description
mediaType HttpMediaType
Returns
Type Description
ProtoHttpContent
Overrides

writeTo(OutputStream out)

public void writeTo(OutputStream out)
Parameter
Name Description
out OutputStream
Exceptions
Type Description
IOException