Class AbstractHttpContent (1.45.1)

public abstract class AbstractHttpContent implements HttpContent

Abstract implementation of an HTTP content with typical options.

Implementation is not thread-safe.

Inheritance

java.lang.Object > AbstractHttpContent

Implements

HttpContent

Static 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.

Parameter
Name Description
content HttpContent

HTTP content

Returns
Type Description
long

computed content length or -1 if retry is not supported

Exceptions
Type Description
IOException

Constructors

AbstractHttpContent(HttpMediaType mediaType)

protected AbstractHttpContent(HttpMediaType mediaType)
Parameter
Name Description
mediaType HttpMediaType

Media type this content represents or null to leave out

AbstractHttpContent(String mediaType)

protected AbstractHttpContent(String mediaType)
Parameter
Name Description
mediaType String

Media type string (for example "type/subtype") this content represents or null to leave out. Can also contain parameters like "charset=utf-8"

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).

Returns
Type Description
long
Exceptions
Type Description
IOException

getCharset()

protected final Charset getCharset()

Returns the charset specified in the media type or ISO_8859_1 if not specified.

Returns
Type Description
Charset

getLength()

public long getLength()

Default implementation calls #computeLength() once and caches it for future invocations, but subclasses may override.

Returns
Type Description
long
Exceptions
Type Description
IOException

getMediaType()

public final HttpMediaType getMediaType()

Returns the media type to use for the Content-Type header, or null if unspecified.

Returns
Type Description
HttpMediaType

getType()

public String getType()

Returns the content type or null for none.

Returns
Type Description
String

retrySupported()

public boolean retrySupported()

Default implementation returns true, but subclasses may override.

Returns
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.

Parameter
Name Description
mediaType HttpMediaType
Returns
Type Description
AbstractHttpContent