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.MessageLite
message
Message 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 long
getLength()
Default implementation callsAbstractHttpContent.computeLength()
once and caches it for future invocations, but subclasses may override.com.google.protobuf.MessageLite
getMessage()
Returns the message to serialize.ProtoHttpContent
setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, ornull
if unspecified.void
writeTo(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.IOException
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:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOException
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:
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: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
-
-