Class ProtoHttpContent
java.lang.Object
com.google.api.client.http.AbstractHttpContent
com.google.api.client.http.protobuf.ProtoHttpContent
- All Implemented Interfaces:
HttpContent
,StreamingContent
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final com.google.protobuf.MessageLite
Message to serialize. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
Default implementation callsAbstractHttpContent.computeLength()
once and caches it for future invocations, but subclasses may override.final com.google.protobuf.MessageLite
Returns the message to serialize.setMediaType
(HttpMediaType mediaType) Sets the media type to use for the Content-Type header, ornull
if unspecified.void
writeTo
(OutputStream out) Writes the byte content to the given output stream.Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, computeLength, getCharset, getMediaType, getType, retrySupported
-
Field Details
-
message
private final com.google.protobuf.MessageLite messageMessage to serialize.
-
-
Constructor Details
-
ProtoHttpContent
public ProtoHttpContent(com.google.protobuf.MessageLite message) - Parameters:
message
- message to serialize
-
-
Method Details
-
getLength
Description copied from class:AbstractHttpContent
Default implementation callsAbstractHttpContent.computeLength()
once and caches it for future invocations, but subclasses may override.- Specified by:
getLength
in interfaceHttpContent
- Overrides:
getLength
in classAbstractHttpContent
- Throws:
IOException
-
writeTo
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
Description copied from class:AbstractHttpContent
Sets the media type to use for the Content-Type header, ornull
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 classAbstractHttpContent
-