Class AbstractHttpEntity
- java.lang.Object
-
- org.apache.hc.core5.http.io.entity.AbstractHttpEntity
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,EntityDetails,HttpEntity
- Direct Known Subclasses:
BasicHttpEntity,ByteArrayEntity,ByteBufferEntity,EntityTemplate,FileEntity,InputStreamEntity,PathEntity,SerializableEntity,StringEntity
public abstract class AbstractHttpEntity extends java.lang.Object implements HttpEntity
Abstract base class for mutable entities. Provides the commonly used attributes for streamed and self-contained implementations.This class contains immutable attributes but subclasses may contain additional immutable or mutable attributes.
- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description private booleanchunkedprivate java.lang.StringcontentEncodingprivate java.lang.StringcontentType(package private) static intOUTPUT_BUFFER_SIZE
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractHttpEntity(java.lang.String contentType, java.lang.String contentEncoding)Constructs a new instance with the given attributes kept as immutable.protectedAbstractHttpEntity(java.lang.String contentType, java.lang.String contentEncoding, boolean chunked)Constructs a new instance with the given attributes kept as immutable.protectedAbstractHttpEntity(ContentType contentType, java.lang.String contentEncoding)Constructs a new instance with the given attributes kept as immutable.protectedAbstractHttpEntity(ContentType contentType, java.lang.String contentEncoding, boolean chunked)Constructs a new instance with the given attributes kept as immutable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetContentEncoding()Gets content encoding of this entity, if known.java.lang.StringgetContentType()Gets content type of this entity, if known.java.util.Set<java.lang.String>getTrailerNames()Gets the preliminary declaration of trailing headers.Supplier<java.util.List<? extends Header>>getTrailers()Gets supplier of message trailers - headers sent after message body.booleanisChunked()Tests the chunked transfer hint for this entity.booleanisRepeatable()Tests if the entity is capable of producing its data more than once.java.lang.StringtoString()voidwriteTo(java.io.OutputStream outStream)Writes this entity to an OutputStream.static voidwriteTo(HttpEntity entity, java.io.OutputStream outStream)Writes an entity to an OutputStream.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.hc.core5.http.EntityDetails
getContentLength
-
Methods inherited from interface org.apache.hc.core5.http.HttpEntity
getContent, isStreaming
-
-
-
-
Field Detail
-
OUTPUT_BUFFER_SIZE
static final int OUTPUT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
contentType
private final java.lang.String contentType
-
contentEncoding
private final java.lang.String contentEncoding
-
chunked
private final boolean chunked
-
-
Constructor Detail
-
AbstractHttpEntity
protected AbstractHttpEntity(java.lang.String contentType, java.lang.String contentEncoding, boolean chunked)Constructs a new instance with the given attributes kept as immutable.- Parameters:
contentType- The content-type string, may be null.contentEncoding- The content encoding string, may be null.chunked- Whether this entity should be chunked.
-
AbstractHttpEntity
protected AbstractHttpEntity(ContentType contentType, java.lang.String contentEncoding, boolean chunked)
Constructs a new instance with the given attributes kept as immutable.- Parameters:
contentType- The content-type, may be null.contentEncoding- The content encoding string, may be null.chunked- Whether this entity should be chunked.
-
AbstractHttpEntity
protected AbstractHttpEntity(java.lang.String contentType, java.lang.String contentEncoding)Constructs a new instance with the given attributes kept as immutable.The new instance:
- is not chunked.
- Parameters:
contentType- The content-type string, may be null.contentEncoding- The content encoding string, may be null.
-
AbstractHttpEntity
protected AbstractHttpEntity(ContentType contentType, java.lang.String contentEncoding)
Constructs a new instance with the given attributes kept as immutable.The new instance:
- is not chunked.
- Parameters:
contentType- The content-type, may be null.contentEncoding- The content encoding string, may be null.
-
-
Method Detail
-
writeTo
public static void writeTo(HttpEntity entity, java.io.OutputStream outStream) throws java.io.IOException
Writes an entity to an OutputStream.- Parameters:
entity- The entity to write, never null.outStream- Where to write the entity, never null.- Throws:
java.io.IOException- if the entity cannot generate its content stream; also thrown if the output stream is closed.java.lang.UnsupportedOperationException- if entity content cannot be represented asInputStream.
-
writeTo
public void writeTo(java.io.OutputStream outStream) throws java.io.IOExceptionWrites this entity to an OutputStream.- Specified by:
writeToin interfaceHttpEntity- Parameters:
outStream- Where to write the entity, never null.- Throws:
java.io.IOException- if the entity cannot generate its content stream; also thrown if the output stream is closed.java.lang.UnsupportedOperationException- if entity content cannot be represented asInputStream.
-
getContentType
public final java.lang.String getContentType()
Description copied from interface:EntityDetailsGets content type of this entity, if known.- Specified by:
getContentTypein interfaceEntityDetails- Returns:
- the content type of this entity, may be
null.
-
getContentEncoding
public final java.lang.String getContentEncoding()
Description copied from interface:EntityDetailsGets content encoding of this entity, if known.- Specified by:
getContentEncodingin interfaceEntityDetails- Returns:
- the content encoding of this entity, may be
null.
-
isChunked
public final boolean isChunked()
Tests the chunked transfer hint for this entity.The behavior of wrapping entities is implementation dependent, but should respect the primary purpose.
This implementation always returns
false.- Specified by:
isChunkedin interfaceEntityDetails- Returns:
- the chunked transfer hint for this entity.
-
isRepeatable
public boolean isRepeatable()
Tests if the entity is capable of producing its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.This implementation always returns
false.- Specified by:
isRepeatablein interfaceHttpEntity- Returns:
- true if the entity is repeatable, false otherwise.
-
getTrailers
public Supplier<java.util.List<? extends Header>> getTrailers()
Gets supplier of message trailers - headers sent after message body. May returnnullif trailers are not available.This implementation always returns
null.- Specified by:
getTrailersin interfaceHttpEntity
-
getTrailerNames
public java.util.Set<java.lang.String> getTrailerNames()
Gets the preliminary declaration of trailing headers.This implementation always returns an immutable empty set.
- Specified by:
getTrailerNamesin interfaceEntityDetails- Returns:
- the preliminary declaration of trailing headers.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-