@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, retrySupportedpublic ProtoHttpContent(com.google.protobuf.MessageLite message)
message - message to serializepublic long getLength()
throws IOException
AbstractHttpContentAbstractHttpContent.computeLength() once and caches it for future
invocations, but subclasses may override.getLength in interface HttpContentgetLength in class AbstractHttpContentIOExceptionpublic void writeTo(OutputStream out) throws IOException
StreamingContentImplementations 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 streamIOExceptionpublic final com.google.protobuf.MessageLite getMessage()
public ProtoHttpContent setMediaType(HttpMediaType mediaType)
AbstractHttpContentnull 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 AbstractHttpContentCopyright © 2011–2021 Google. All rights reserved.