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.
|
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. |
protected Charset |
getCharset()
Returns the charset specified in the media type or ISO_8859_1 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 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, wait
writeTo
protected 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 long getLength() throws IOException
computeLength()
once and caches it for future
invocations, but subclasses may override.getLength
in interface HttpContent
IOException
public 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()
public String getType()
HttpContent
null
for none.getType
in interface HttpContent
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.retrySupported
in interface HttpContent
public static long computeLength(HttpContent content) 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 supportedIOException
Copyright © 2011–2022 Google. All rights reserved.