Top Description Fields Constructors Methods
org.apache.hc.client5.http.entity

public Class EntityBuilder

extends Object
Class Inheritance
Imports
java.io.File, .InputStream, .Serializable, java.util.Arrays, .List, org.apache.hc.core5.http.ContentType, .HttpEntity, .NameValuePair, org.apache.hc.core5.http.io.entity.AbstractHttpEntity, .ByteArrayEntity, .FileEntity, .InputStreamEntity, .SerializableEntity, .StringEntity

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:

Since
4.3

Field Summary

Modifier and TypeField and Description
private byte[]
private boolean
private String
private ContentType
private File
private boolean
private List<NameValuePair>
private Serializable
private InputStream
private String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public HttpEntity

Returns:

a new instance.
build
()

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

public EntityBuilder

Returns:

this
chunked
()

Sets entities to be chunked.

private void
public static EntityBuilder
public byte[]

Returns:

entity content as a byte array.
getBinary
()

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

public String

Returns:

the content encoding of the entity, may be null.
getContentEncoding
()

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

private ContentType
public ContentType

Returns:

the ContentType of the entity, may be null.
getContentType
()

Gets the ContentType of the entity, may be null.

public File

Returns:

Gets the entity content as a File.
getFile
()

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

public List<NameValuePair>

Returns:

entity content as a parameter list.
getParameters
()

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

public Serializable

Returns:

entity content as a Serializable.
getSerializable
()

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

public InputStream

Returns:

entity content as an InputStream
getStream
()

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

public String

Returns:

the entity content as a string, may be null.
getText
()

Gets the entity content as a string if set using setText(String).

public EntityBuilder

Returns:

this
gzipCompressed
()

Sets entities to be GZIP compressed.

public boolean

Returns:

true if entity is to be chunk coded, false otherwise.
isChunked
()

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

public boolean

Returns:

true if entity is to be GZIP compressed, false otherwise.
isGzipCompressed
()

Tests if entities are to be GZIP compressed (true), or not (false).

public EntityBuilder

Returns:

this
setBinary
(final byte[]
The new entity content as a byte array.
binary
)

Sets entity content as a byte array.

public EntityBuilder

Returns:

this
setContentEncoding
(final String
the content encoding of the entity, may be null.
contentEncoding
)

Sets the content encoding of the entity.

public EntityBuilder

Returns:

this
setContentType
(final ContentType
the ContentType of the entity, may be null.
contentType
)

Sets the ContentType of the entity.

public EntityBuilder

Returns:

this
setFile
(final File
entity content as a File.
file
)

Sets entity content as a File.

public EntityBuilder

Returns:

this
setParameters
(final List<NameValuePair>
entity content as a parameter list.
parameters
)

Sets entity content as a parameter list.

public EntityBuilder

Returns:

this
setParameters
(final NameValuePair...
entity content as a parameter list.
parameters
)

Sets entity content as a parameter list.

public EntityBuilder

Returns:

this
setSerializable
(final Serializable
entity content as a Serializable.
serializable
)

Sets entity content as a Serializable.

public EntityBuilder

Returns:

this
setStream
(final InputStream
The new entity content as an InputStream.
stream
)

Sets entity content as an InputStream.

public EntityBuilder

Returns:

this
setText
(final String
entity content as a string.
text
)

Sets entity content as a string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

binaryback to summary
private byte[] binary
chunkedback to summary
private boolean chunked
contentEncodingback to summary
private String contentEncoding
contentTypeback to summary
private ContentType contentType
fileback to summary
private File file
gzipCompressedback to summary
private boolean gzipCompressed
parametersback to summary
private List<NameValuePair> parameters
serializableback to summary
private Serializable serializable
streamback to summary
private InputStream stream
textback to summary
private String text

Constructor Detail

EntityBuilderback to summary
pack-priv EntityBuilder()

Method Detail

buildback to summary
public HttpEntity build()

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

Returns:HttpEntity

a new instance.

chunkedback to summary
public EntityBuilder chunked()

Sets entities to be chunked.

Returns:EntityBuilder

this

clearContentback to summary
private void clearContent()
createback to summary
public static EntityBuilder create()
getBinaryback to summary
public byte[] getBinary()

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

Returns:byte[]

entity content as a byte array.

getContentEncodingback to summary
public String getContentEncoding()

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

Returns:String

the content encoding of the entity, may be null.

getContentOrDefaultback to summary
private ContentType getContentOrDefault(final ContentType def)
getContentTypeback to summary
public ContentType getContentType()

Gets the ContentType of the entity, may be null.

Returns:ContentType

the ContentType of the entity, may be null.

getFileback to summary
public File getFile()

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

Returns:File

Gets the entity content as a File.

getParametersback to summary
public List<NameValuePair> getParameters()

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

Returns:List<NameValuePair>

entity content as a parameter list.

getSerializableback to summary
public Serializable getSerializable()

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

Returns:Serializable

entity content as a Serializable.

getStreamback to summary
public InputStream getStream()

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

Returns:InputStream

entity content as an InputStream

getTextback to summary
public String getText()

Gets the entity content as a string if set using setText(String).

Returns:String

the entity content as a string, may be null.

gzipCompressedback to summary
public EntityBuilder gzipCompressed()

Sets entities to be GZIP compressed.

Returns:EntityBuilder

this

isChunkedback to summary
public boolean isChunked()

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

Returns:boolean

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

isGzipCompressedback to summary
public boolean isGzipCompressed()

Tests if entities are to be GZIP compressed (true), or not (false).

Returns:boolean

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

setBinaryback to summary
public EntityBuilder setBinary(final 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:byte[]

The new entity content as a byte array.

Returns:EntityBuilder

this

setContentEncodingback to summary
public EntityBuilder setContentEncoding(final String contentEncoding)

Sets the content encoding of the entity.

Parameters
contentEncoding:String

the content encoding of the entity, may be null.

Returns:EntityBuilder

this

setContentTypeback to summary
public EntityBuilder setContentType(final ContentType contentType)

Sets the ContentType of the entity.

Parameters
contentType:ContentType

the ContentType of the entity, may be null.

Returns:EntityBuilder

this

setFileback to summary
public EntityBuilder setFile(final 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:File

entity content as a File.

Returns:EntityBuilder

this

setParametersback to summary
public EntityBuilder setParameters(final 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:List<NameValuePair>

entity content as a parameter list.

Returns:EntityBuilder

this

setParametersback to summary
public EntityBuilder setParameters(final 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:NameValuePair[]

entity content as a parameter list.

Returns:EntityBuilder

this

setSerializableback to summary
public EntityBuilder setSerializable(final 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:Serializable

entity content as a Serializable.

Returns:EntityBuilder

this

setStreamback to summary
public EntityBuilder setStream(final 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:InputStream

The new entity content as an InputStream.

Returns:EntityBuilder

this

setTextback to summary
public EntityBuilder setText(final 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:String

entity content as a string.

Returns:EntityBuilder

this