Class ProtoHttpContent
- java.lang.Object
-
- com.google.api.client.http.AbstractHttpContent
-
- com.google.api.client.http.protobuf.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 Summary
Fields Modifier and Type Field Description private com.google.protobuf.MessageLitemessageMessage to serialize.
-
Constructor Summary
Constructors Constructor Description ProtoHttpContent(com.google.protobuf.MessageLite message)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetLength()Default implementation callsAbstractHttpContent.computeLength()once and caches it for future invocations, but subclasses may override.com.google.protobuf.MessageLitegetMessage()Returns the message to serialize.ProtoHttpContentsetMediaType(HttpMediaType mediaType)Sets the media type to use for the Content-Type header, ornullif unspecified.voidwriteTo(java.io.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
-
-
-
-
Method Detail
-
getLength
public long getLength() throws java.io.IOExceptionDescription copied from class:AbstractHttpContentDefault implementation callsAbstractHttpContent.computeLength()once and caches it for future invocations, but subclasses may override.- Specified by:
getLengthin interfaceHttpContent- Overrides:
getLengthin classAbstractHttpContent- Throws:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionDescription copied from interface:StreamingContentWrites 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:AbstractHttpContentSets the media type to use for the Content-Type header, ornullif 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:
setMediaTypein classAbstractHttpContent
-
-