org.apache.http.client.entity

## Class EntityBuilder

- java.lang.Object
- - org.apache.http.client.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(org.apache.http.NameValuePair...)`
  - `setFile(java.io.File)`
  Since:
    4.3

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.apache.http.HttpEntity` | `build()` Creates new instance of `HttpEntity` based on the current state.
    `EntityBuilder` | `chunked()` Makes entity chunk coded.
    `static EntityBuilder` | `create()`
    `byte[]` | `getBinary()` Returns entity content as a byte array if set using `setBinary(byte[])` method.
    `String` | `getContentEncoding()` Returns content encoding of the entity, if set.
    `org.apache.http.entity.ContentType` | `getContentType()` Returns `ContentType` of the entity, if set.
    `File` | `getFile()` Returns entity content as a `File` if set using `setFile(java.io.File)` method.
    `List<org.apache.http.NameValuePair>` | `getParameters()` Returns entity content as a parameter list if set using `setParameters(java.util.List)` or `setParameters(org.apache.http.NameValuePair...)` methods.
    `Serializable` | `getSerializable()` Returns entity content as a `Serializable` if set using `setSerializable(java.io.Serializable)` method.
    `InputStream` | `getStream()` Returns entity content as a `InputStream` if set using `setStream(java.io.InputStream)` method.
    `String` | `getText()` Returns entity content as a string if set using `setText(String)` method.
    `EntityBuilder` | `gzipCompress()` Makes entity GZIP compressed.
    `boolean` | `isChunked()` Returns `true` if entity is to be chunk coded, `false` otherwise.
    `boolean` | `isGzipCompress()` Returns `true` if entity is to be GZIP compressed, `false` otherwise.
    `EntityBuilder` | `setBinary(byte[] binary)` Sets entity content as a byte array.
    `EntityBuilder` | `setContentEncoding(String contentEncoding)` Sets content encoding of the entity.
    `EntityBuilder` | `setContentType(org.apache.http.entity.ContentType contentType)` Sets `ContentType` of the entity.
    `EntityBuilder` | `setFile(File file)` Sets entity content as a `File`.
    `EntityBuilder` | `setParameters(List<org.apache.http.NameValuePair> parameters)` Sets entity content as a parameter list.
    `EntityBuilder` | `setParameters(org.apache.http.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 a `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()

      Returns entity content as a string if set using `setText(String)` method.

    - #### 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(org.apache.http.NameValuePair...)`
      - `setFile(java.io.File)`

    - #### getBinary

          public byte[] getBinary()

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

    - #### 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(org.apache.http.NameValuePair...)`
      - `setFile(java.io.File)`

    - #### getStream

          public InputStream getStream()

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

    - #### setStream

          public EntityBuilder setStream(InputStream stream)

      Sets entity content as a `InputStream`. This method is mutually exclusive with:
      - `setText(String)`
      - `setBinary(byte[])`
      - `setSerializable(java.io.Serializable)`
      - `setParameters(java.util.List)`
      - `setParameters(org.apache.http.NameValuePair...)`
      - `setFile(java.io.File)`

    - #### getParameters

          public List<org.apache.http.NameValuePair> getParameters()

      Returns entity content as a parameter list if set using `setParameters(java.util.List)` or `setParameters(org.apache.http.NameValuePair...)` methods.

    - #### setParameters

          public EntityBuilder setParameters(List<org.apache.http.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)`

    - #### setParameters

          public EntityBuilder setParameters(org.apache.http.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)`

    - #### getSerializable

          public Serializable getSerializable()

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

    - #### 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(org.apache.http.NameValuePair...)`
      - `setFile(java.io.File)`

    - #### getFile

          public File getFile()

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

    - #### 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(org.apache.http.NameValuePair...)`
      - `setSerializable(java.io.Serializable)`

    - #### getContentType

          public org.apache.http.entity.ContentType getContentType()

      Returns `ContentType` of the entity, if set.

    - #### setContentType

          public EntityBuilder setContentType(org.apache.http.entity.ContentType contentType)

      Sets `ContentType` of the entity.

    - #### getContentEncoding

          public String getContentEncoding()

      Returns content encoding of the entity, if set.

    - #### setContentEncoding

          public EntityBuilder setContentEncoding(String contentEncoding)

      Sets content encoding of the entity.

    - #### isChunked

          public boolean isChunked()

      Returns `true` if entity is to be chunk coded, `false` otherwise.

    - #### chunked

          public EntityBuilder chunked()

      Makes entity chunk coded.

    - #### isGzipCompress

          public boolean isGzipCompress()

      Returns `true` if entity is to be GZIP compressed, `false` otherwise.

    - #### gzipCompress

          public EntityBuilder gzipCompress()

      Makes entity GZIP compressed.

    - #### build

          public org.apache.http.HttpEntity build()

      Creates new instance of `HttpEntity` based on the current state.

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