org.apache.hc.core5.http.io.entity

## Class AbstractHttpEntity

- java.lang.Object
- - org.apache.hc.core5.http.io.entity.AbstractHttpEntity

- All Implemented Interfaces:
    Closeable, AutoCloseable, EntityDetails, HttpEntity
  Direct Known Subclasses:
    BasicHttpEntity, ByteArrayEntity, ByteBufferEntity, EntityTemplate, FileEntity, InputStreamEntity, PathEntity, SerializableEntity, StringEntity

      public abstract class AbstractHttpEntity
      extends 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

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractHttpEntity(ContentType contentType, String contentEncoding)` Constructs a new instance with the given attributes kept as immutable.
    `protected` | `AbstractHttpEntity(ContentType contentType, String contentEncoding, boolean chunked)` Constructs a new instance with the given attributes kept as immutable.
    `protected` | `AbstractHttpEntity(String contentType, String contentEncoding)` Constructs a new instance with the given attributes kept as immutable.
    `protected` | `AbstractHttpEntity(String contentType, 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 and Description
    --- | ---
    `String` | `getContentEncoding()` Gets content encoding of this entity, if known.
    `String` | `getContentType()` Gets content type of this entity, if known.
    `Set<String>` | `getTrailerNames()` Gets the preliminary declaration of trailing headers.
    `Supplier<List<? extends Header>>` | `getTrailers()` Gets supplier of message trailers - headers sent after message body.
    `boolean` | `isChunked()` Tests the chunked transfer hint for this entity.
    `boolean` | `isRepeatable()` Tests if the entity is capable of producing its data more than once.
    `String` | `toString()`
    `static void` | `writeTo(HttpEntity entity, OutputStream outStream)` Writes an entity to an OutputStream.
    `void` | `writeTo(OutputStream outStream)` Writes this 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.HttpEntity

      `getContent, isStreaming`

    - ### Methods inherited from interface org.apache.hc.core5.http.EntityDetails

      `getContentLength`

    - ### Methods inherited from interface java.io.Closeable

      `close`

- - ### Constructor Detail

    - #### AbstractHttpEntity

          protected AbstractHttpEntity(String contentType,
                                       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,
                                       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(String contentType,
                                       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,
                                       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,
                                     OutputStream outStream)
                              throws IOException

      Writes an entity to an OutputStream.
      Parameters:
        `entity` - The entity to write, never null.
        `outStream` - Where to write the entity, never null.
      Throws:
        `IOException` - if the entity cannot generate its content stream; also thrown if the output stream is closed.
        `UnsupportedOperationException` - if entity content cannot be represented as `InputStream`.

    - #### writeTo

          public void writeTo(OutputStream outStream)
                       throws IOException

      Writes this entity to an OutputStream.
      Specified by:
        `writeTo` in interface `HttpEntity`
      Parameters:
        `outStream` - Where to write the entity, never null.
      Throws:
        `IOException` - if the entity cannot generate its content stream; also thrown if the output stream is closed.
        `UnsupportedOperationException` - if entity content cannot be represented as `InputStream`.

    - #### getContentType

          public final String getContentType()

      Description copied from interface: `EntityDetails`
      Gets content type of this entity, if known.
      Specified by:
        `getContentType` in interface `EntityDetails`
      Returns:
        the content type of this entity, may be `null`.

    - #### getContentEncoding

          public final String getContentEncoding()

      Description copied from interface: `EntityDetails`
      Gets content encoding of this entity, if known.
      Specified by:
        `getContentEncoding` in interface `EntityDetails`
      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:
        `isChunked` in interface `EntityDetails`
      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:
        `isRepeatable` in interface `HttpEntity`
      Returns:
        true if the entity is repeatable, false otherwise.

    - #### getTrailers

          public Supplier<List<? extends Header>> getTrailers()

      Gets supplier of message trailers - headers sent after message body. May return `null` if trailers are not available.

      This implementation always returns `null`.

      Specified by:
        `getTrailers` in interface `HttpEntity`

    - #### getTrailerNames

          public Set<String> getTrailerNames()

      Gets the preliminary declaration of trailing headers.

      This implementation always returns an immutable empty set.

      Specified by:
        `getTrailerNames` in interface `EntityDetails`
      Returns:
        the preliminary declaration of trailing headers.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.