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.
Constructors
ProtoHttpContent(MessageLite message)
public ProtoHttpContent(MessageLite message)
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.
Type | Description |
long |
Type | Description |
IOException |
getMessage()
public final MessageLite getMessage()
Returns the message to serialize.
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.
Name | Description |
mediaType | HttpMediaType |
Type | Description |
ProtoHttpContent |
writeTo(OutputStream out)
public void writeTo(OutputStream out)
Name | Description |
out | OutputStream |
Type | Description |
IOException |