public abstract class AbstractHttpContent implements HttpContent
Abstract implementation of an HTTP content with typical options.
Implementation is not thread-safe.
Implements
HttpContentStatic Methods
computeLength(HttpContent content)
public static long computeLength(HttpContent content)
Returns the computed content length based using IOUtils#computeLength(StreamingContent)
or instead -1
if HttpContent#retrySupported() is false
because the
stream must not be read twice.
Name | Description |
content | HttpContent HTTP content |
Type | Description |
long | computed content length or |
Type | Description |
IOException |
Constructors
AbstractHttpContent(HttpMediaType mediaType)
protected AbstractHttpContent(HttpMediaType mediaType)
Name | Description |
mediaType | HttpMediaType Media type this content represents or |
AbstractHttpContent(String mediaType)
protected AbstractHttpContent(String mediaType)
Name | Description |
mediaType | String Media type string (for example "type/subtype") this content represents or
|
Methods
computeLength()
protected long 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).
Type | Description |
long |
Type | Description |
IOException |
getCharset()
protected final Charset getCharset()
Returns the charset specified in the media type or ISO_8859_1 if not specified.
Type | Description |
Charset |
getLength()
public long getLength()
Default implementation calls #computeLength() once and caches it for future invocations, but subclasses may override.
Type | Description |
long |
Type | Description |
IOException |
getMediaType()
public final HttpMediaType getMediaType()
Returns the media type to use for the Content-Type header, or null
if unspecified.
Type | Description |
HttpMediaType |
getType()
public String getType()
Returns the content type or null
for none.
Type | Description |
String |
retrySupported()
public boolean retrySupported()
Default implementation returns true
, but subclasses may override.
Type | Description |
boolean |
setMediaType(HttpMediaType mediaType)
public AbstractHttpContent setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, or 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.
Name | Description |
mediaType | HttpMediaType |
Type | Description |
AbstractHttpContent |