org.apache.hc.client5.http.entity

## Class EntityBuilder

- java.lang.Object
- - org.apache.hc.client5.http.entity.EntityBuilder

-     public class EntityBuilder
      extends Object

  Builder for `HttpEntity` instances.

  Several setter methods of this builder are mutually exclusive. In case of multiple invocations of the following methods only the last one will have effect:

  - `setText(String)`
  - `setBinary(byte[])`
  - `setStream(java.io.InputStream)`
  - `setSerializable(java.io.Serializable)`
  - `setParameters(java.util.List)`
  - `setParameters(NameValuePair...)`
  - `setFile(java.io.File)`
  Since:
    4.3

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `HttpEntity` | `build()` Builds a new instance of `HttpEntity` based on the current state.
    `EntityBuilder` | `chunked()` Sets entities to be chunked.
    `static EntityBuilder` | `create()`
    `byte[]` | `getBinary()` Gets entity content as a byte array if set using `setBinary(byte[])`.
    `String` | `getContentEncoding()` Gets the content encoding of the entity, may be null.
    `ContentType` | `getContentType()` Gets the `ContentType` of the entity, may be null.
    `File` | `getFile()` Gets the entity content as a `File` if set using `setFile(java.io.File)`.
    `List<NameValuePair>` | `getParameters()` Gets entity content as a parameter list if set using `setParameters(java.util.List)` or `setParameters(NameValuePair...)`.
    `Serializable` | `getSerializable()` Gets entity content as a `Serializable` if set using `setSerializable(java.io.Serializable)` method.
    `InputStream` | `getStream()` Gets entity content as an `InputStream` if set using `setStream(java.io.InputStream)` method.
    `String` | `getText()` Gets the entity content as a string if set using `setText(String)`.
    `EntityBuilder` | `gzipCompressed()` Sets entities to be GZIP compressed.
    `boolean` | `isChunked()` Tests if the entity is to be chunk coded (`true`), or not (`false`).
    `boolean` | `isGzipCompressed()` Tests if entities are to be GZIP compressed (`true`), or not (`false`).
    `EntityBuilder` | `setBinary(byte[] binary)` Sets entity content as a byte array.
    `EntityBuilder` | `setContentEncoding(String contentEncoding)` Sets the content encoding of the entity.
    `EntityBuilder` | `setContentType(ContentType contentType)` Sets the `ContentType` of the entity.
    `EntityBuilder` | `setFile(File file)` Sets entity content as a `File`.
    `EntityBuilder` | `setParameters(List<NameValuePair> parameters)` Sets entity content as a parameter list.
    `EntityBuilder` | `setParameters(NameValuePair... parameters)` Sets entity content as a parameter list.
    `EntityBuilder` | `setSerializable(Serializable serializable)` Sets entity content as a `Serializable`.
    `EntityBuilder` | `setStream(InputStream stream)` Sets entity content as an `InputStream`.
    `EntityBuilder` | `setText(String text)` Sets entity content as a string.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### create

          public static EntityBuilder create()

    - #### getText

          public String getText()

      Gets the entity content as a string if set using `setText(String)`.
      Returns:
        the entity content as a string, may be null.

    - #### setText

          public EntityBuilder setText(String text)

      Sets entity content as a string. This method is mutually exclusive with `setBinary(byte[])`, `setStream(java.io.InputStream)`, `setSerializable(java.io.Serializable)`, `setParameters(java.util.List)`, `setParameters(NameValuePair...)` `setFile(java.io.File)` methods.
      Parameters:
        `text` - entity content as a string.
      Returns:
        this

    - #### getBinary

          public byte[] getBinary()

      Gets entity content as a byte array if set using `setBinary(byte[])`.
      Returns:
        entity content as a byte array.

    - #### setBinary

          public EntityBuilder setBinary(byte[] binary)

      Sets entity content as a byte array. This method is mutually exclusive with `setText(String)`, `setStream(java.io.InputStream)`, `setSerializable(java.io.Serializable)`, `setParameters(java.util.List)`, `setParameters(NameValuePair...)` `setFile(java.io.File)`.
      Parameters:
        `binary` - The new entity content as a byte array.
      Returns:
        this

    - #### getStream

          public InputStream getStream()

      Gets entity content as an `InputStream` if set using `setStream(java.io.InputStream)` method.
      Returns:
        entity content as an `InputStream`

    - #### setStream

          public EntityBuilder setStream(InputStream stream)

      Sets entity content as an `InputStream`. This method is mutually exclusive with `setText(String)`, `setBinary(byte[])`, `setSerializable(java.io.Serializable)`, `setParameters(java.util.List)`, `setParameters(NameValuePair...)` `setFile(java.io.File)`.
      Parameters:
        `stream` - The new entity content as an InputStream.
      Returns:
        this

    - #### getParameters

          public List<NameValuePair> getParameters()

      Gets entity content as a parameter list if set using `setParameters(java.util.List)` or `setParameters(NameValuePair...)`.
      Returns:
        entity content as a parameter list.

    - #### setParameters

          public EntityBuilder setParameters(List<NameValuePair> parameters)

      Sets entity content as a parameter list. This method is mutually exclusive with `setText(String)`, `setBinary(byte[])`, `setStream(java.io.InputStream)`, `setSerializable(java.io.Serializable)`, `setFile(java.io.File)`.
      Parameters:
        `parameters` - entity content as a parameter list.
      Returns:
        this

    - #### setParameters

          public EntityBuilder setParameters(NameValuePair... parameters)

      Sets entity content as a parameter list. This method is mutually exclusive with `setText(String)`, `setBinary(byte[])`, `setStream(java.io.InputStream)`, `setSerializable(java.io.Serializable)`, `setFile(java.io.File)`.
      Parameters:
        `parameters` - entity content as a parameter list.
      Returns:
        this

    - #### getSerializable

          public Serializable getSerializable()

      Gets entity content as a `Serializable` if set using `setSerializable(java.io.Serializable)` method.
      Returns:
        entity content as a `Serializable`.

    - #### setSerializable

          public EntityBuilder setSerializable(Serializable serializable)

      Sets entity content as a `Serializable`. This method is mutually exclusive with `setText(String)`, `setBinary(byte[])`, `setStream(java.io.InputStream)`, `setParameters(java.util.List)`, `setParameters(NameValuePair...)` `setFile(java.io.File)`.
      Parameters:
        `serializable` - entity content as a `Serializable`.
      Returns:
        this

    - #### getFile

          public File getFile()

      Gets the entity content as a `File` if set using `setFile(java.io.File)`.
      Returns:
        Gets the entity content as a `File`.

    - #### setFile

          public EntityBuilder setFile(File file)

      Sets entity content as a `File`. This method is mutually exclusive with `setText(String)`, `setBinary(byte[])`, `setStream(java.io.InputStream)`, `setParameters(java.util.List)`, `setParameters(NameValuePair...)` `setSerializable(java.io.Serializable)`.
      Parameters:
        `file` - entity content as a `File`.
      Returns:
        this

    - #### getContentType

          public ContentType getContentType()

      Gets the `ContentType` of the entity, may be null.
      Returns:
        the `ContentType` of the entity, may be null.

    - #### setContentType

          public EntityBuilder setContentType(ContentType contentType)

      Sets the `ContentType` of the entity.
      Parameters:
        `contentType` - the `ContentType` of the entity, may be null.
      Returns:
        this

    - #### getContentEncoding

          public String getContentEncoding()

      Gets the content encoding of the entity, may be null.
      Returns:
        the content encoding of the entity, may be null.

    - #### setContentEncoding

          public EntityBuilder setContentEncoding(String contentEncoding)

      Sets the content encoding of the entity.
      Parameters:
        `contentEncoding` - the content encoding of the entity, may be null.
      Returns:
        this

    - #### isChunked

          public boolean isChunked()

      Tests if the entity is to be chunk coded (`true`), or not (`false`).
      Returns:
        `true` if entity is to be chunk coded, `false` otherwise.

    - #### chunked

          public EntityBuilder chunked()

      Sets entities to be chunked.
      Returns:
        this

    - #### isGzipCompressed

          public boolean isGzipCompressed()

      Tests if entities are to be GZIP compressed (`true`), or not (`false`).
      Returns:
        `true` if entity is to be GZIP compressed, `false` otherwise.

    - #### gzipCompressed

          public EntityBuilder gzipCompressed()

      Sets entities to be GZIP compressed.
      Returns:
        this

    - #### build

          public HttpEntity build()

      Builds a new instance of `HttpEntity` based on the current state.
      Returns:
        a new instance.

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