public abstract class AbstractHttpContent extends Objectimplements HttpContent
Implementation is not thread-safe.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHttpContent(HttpMediaType
|
protected |
AbstractHttpContent(String
|
| Modifier and Type | Method and Description |
|---|---|
protected long |
computeLength()
Computes and returns the content length or less than zero if not known.
|
static long |
computeLength(HttpContent
Returns the computed content length based using
IOUtils or instead
-1 if
HttpContent is
false because the stream must not be read twice.
|
protected Charset |
getCharset()
Returns the charset specified in the media type or
Charsets#UTF_8 if not specified.
|
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
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(StringmediaType)
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(HttpMediaTypemediaType)
mediaType - Media type this content represents or
null to leave out
public long getLength()
throws IOException
computeLength() once and caches it for future invocations, but subclasses may override.
getLength in interface
HttpContent
IOException
public final HttpMediaTypegetMediaType()
null if unspecified.
public AbstractHttpContentsetMediaType(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 CharsetgetCharset()
Charsets#UTF_8 if not specified.
public StringgetType()
HttpContent
null for none.
protected long computeLength()
throws IOException
Subclasses may override, but by default this computes the length by calling computeLength(HttpContent).
IOException
public boolean retrySupported()
true, but subclasses may override.
public static long computeLength(HttpContentcontent) throws IOException
IOUtils.computeLength(StreamingContent) or instead
-1 if
HttpContent.retrySupported() is
false because the stream must not be read twice.
content - HTTP content
-1 if retry is not supported
IOException