@Beta public class ProtoHttpContent extends AbstractHttpContent
Beta
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.
Constructor and Description |
---|
ProtoHttpContent(com.google.protobuf.MessageLite message) |
Modifier and Type | Method and Description |
---|---|
long |
getLength()
Default implementation calls
AbstractHttpContent.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, or
null if unspecified. |
void |
writeTo(OutputStream out)
Writes the byte content to the given output stream.
|
computeLength, computeLength, getCharset, getMediaType, getType, retrySupported
public ProtoHttpContent(com.google.protobuf.MessageLite message)
message
- message to serializepublic long getLength() throws IOException
AbstractHttpContent
AbstractHttpContent.computeLength()
once and caches it for future
invocations, but subclasses may override.getLength
in interface HttpContent
getLength
in class AbstractHttpContent
IOException
public void writeTo(OutputStream out) throws IOException
StreamingContent
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.
out
- output streamIOException
public final com.google.protobuf.MessageLite getMessage()
public ProtoHttpContent setMediaType(HttpMediaType mediaType)
AbstractHttpContent
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.
setMediaType
in class AbstractHttpContent
Copyright © 2011–2019 Google. All rights reserved.