Class AbstractHttpContent
java.lang.Object
com.google.api.client.http.AbstractHttpContent
- All Implemented Interfaces:
HttpContent, StreamingContent
- Direct Known Subclasses:
AbstractXmlHttpContent, JsonHttpContent, MultipartContent, ProtoHttpContent, UrlEncodedContent
Abstract implementation of an HTTP content with typical options.
Implementation is not thread-safe.
- Since:
- 1.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longCached value for the computed length fromcomputeLength().private HttpMediaTypeMedia type used for the Content-Type header ornullfor none. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractHttpContent(HttpMediaType mediaType) protectedAbstractHttpContent(String mediaType) -
Method Summary
Modifier and TypeMethodDescriptionprotected longComputes and returns the content length or less than zero if not known.static longcomputeLength(HttpContent content) Returns the computed content length based usingIOUtils.computeLength(StreamingContent)or instead-1ifHttpContent.retrySupported()isfalsebecause the stream must not be read twice.protected final CharsetReturns the charset specified in the media type or ISO_8859_1 if not specified.longDefault implementation callscomputeLength()once and caches it for future invocations, but subclasses may override.final HttpMediaTypeReturns the media type to use for the Content-Type header, ornullif unspecified.getType()Returns the content type ornullfor none.booleanDefault implementation returnstrue, but subclasses may override.setMediaType(HttpMediaType mediaType) Sets the media type to use for the Content-Type header, ornullif unspecified.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpContent
writeTo
-
Field Details
-
mediaType
Media type used for the Content-Type header ornullfor none. -
computedLength
private long computedLengthCached value for the computed length fromcomputeLength().
-
-
Constructor Details
-
AbstractHttpContent
- Parameters:
mediaType- Media type string (for example "type/subtype") this content represents ornullto leave out. Can also contain parameters like"charset=utf-8"- Since:
- 1.10
-
AbstractHttpContent
- Parameters:
mediaType- Media type this content represents ornullto leave out- Since:
- 1.10
-
-
Method Details
-
getLength
Default implementation callscomputeLength()once and caches it for future invocations, but subclasses may override.- Specified by:
getLengthin interfaceHttpContent- Throws:
IOException
-
getMediaType
Returns the media type to use for the Content-Type header, ornullif unspecified.- Since:
- 1.10
-
setMediaType
Sets 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.- Since:
- 1.10
-
getCharset
Returns the charset specified in the media type or ISO_8859_1 if not specified.- Since:
- 1.10
-
getType
Description copied from interface:HttpContentReturns the content type ornullfor none.- Specified by:
getTypein interfaceHttpContent
-
computeLength
Computes and returns the content length or less than zero if not known.Subclasses may override, but by default this computes the length by calling
computeLength(HttpContent).- Throws:
IOException
-
retrySupported
public boolean retrySupported()Default implementation returnstrue, but subclasses may override.- Specified by:
retrySupportedin interfaceHttpContent
-
computeLength
Returns the computed content length based usingIOUtils.computeLength(StreamingContent)or instead-1ifHttpContent.retrySupported()isfalsebecause the stream must not be read twice.- Parameters:
content- HTTP content- Returns:
- computed content length or
-1if retry is not supported - Throws:
IOException- Since:
- 1.14
-