public abstract class AbstractHttpContent extends Object implements HttpContent
Implementation is not thread-safe.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHttpContent(HttpMediaType mediaType) |
protected |
AbstractHttpContent(String mediaType) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
computeLength()
Computes and returns the content length or less than zero if not known.
|
protected Charset |
getCharset()
Returns the charset specified in the media type or
Charsets#UTF_8 if not specified. |
String |
getEncoding()
Default implementation returns
null, but subclasses may override. |
long |
getLength()
Default implementation calls
computeLength() once and caches it for future
invocations, but subclasses may override. |
HttpMediaType |
getMediaType()
Returns the media type to use for the Content-Type header, or
null if unspecified. |
String |
getType()
Returns the content type or
null for none. |
boolean |
retrySupported()
Default implementation returns
true, but subclasses may override. |
AbstractHttpContent |
setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, or
null if unspecified. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitwriteToprotected AbstractHttpContent(String mediaType)
mediaType - Media type string (for example "type/subtype") this content represents or
null to leave out. Can also contain parameters like "charset=utf-8"protected AbstractHttpContent(HttpMediaType mediaType)
mediaType - Media type this content represents or null to leave outpublic String getEncoding()
null, but subclasses may override.getEncoding in interface HttpContentpublic long getLength()
throws IOException
computeLength() once and caches it for future
invocations, but subclasses may override.getLength in interface HttpContentIOExceptionpublic final HttpMediaType getMediaType()
null if unspecified.public AbstractHttpContent setMediaType(HttpMediaType mediaType)
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.
protected final Charset getCharset()
Charsets#UTF_8 if not specified.public String getType()
HttpContentnull for none.getType in interface HttpContentprotected long computeLength()
throws IOException
Subclasses may override, but by default this computes the length by calling
HttpContent.writeTo(OutputStream) with an output stream that does not process the bytes written,
but only retains the count of bytes. If retrySupported() is false, it will
instead return -1.
IOExceptionpublic boolean retrySupported()
true, but subclasses may override.retrySupported in interface HttpContentCopyright © 2011-2012 Google. All Rights Reserved.