public class EntityBuilder
extends java.lang.Object
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:
Modifier and Type | Field and Description |
---|---|
private byte[] |
binary |
private boolean |
chunked |
private java.lang.String |
contentEncoding |
private org.apache.http.entity.ContentType |
contentType |
private java.io.File |
file |
private boolean |
gzipCompress |
private java.util.List<org.apache.http.NameValuePair> |
parameters |
private java.io.Serializable |
serializable |
private java.io.InputStream |
stream |
private java.lang.String |
text |
Constructor and Description |
---|
EntityBuilder() |
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.
|
private void |
clearContent() |
static EntityBuilder |
create() |
byte[] |
getBinary()
Returns entity content as a byte array if set using
setBinary(byte[]) method. |
java.lang.String |
getContentEncoding()
Returns content encoding of the entity, if set.
|
private org.apache.http.entity.ContentType |
getContentOrDefault(org.apache.http.entity.ContentType def) |
org.apache.http.entity.ContentType |
getContentType()
Returns
ContentType of the entity, if set. |
java.io.File |
getFile()
Returns entity content as a
File if set using
setFile(java.io.File) method. |
java.util.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. |
java.io.Serializable |
getSerializable()
Returns entity content as a
Serializable if set using
setSerializable(java.io.Serializable) method. |
java.io.InputStream |
getStream()
Returns entity content as a
InputStream if set using
setStream(java.io.InputStream) method. |
java.lang.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(java.lang.String contentEncoding)
Sets content encoding of the entity.
|
EntityBuilder |
setContentType(org.apache.http.entity.ContentType contentType)
Sets
ContentType of the entity. |
EntityBuilder |
setFile(java.io.File file)
Sets entity content as a
File . |
EntityBuilder |
setParameters(java.util.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(java.io.Serializable serializable)
Sets entity content as a
Serializable . |
EntityBuilder |
setStream(java.io.InputStream stream)
Sets entity content as a
InputStream . |
EntityBuilder |
setText(java.lang.String text)
Sets entity content as a string.
|
private java.lang.String text
private byte[] binary
private java.io.InputStream stream
private java.util.List<org.apache.http.NameValuePair> parameters
private java.io.Serializable serializable
private java.io.File file
private org.apache.http.entity.ContentType contentType
private java.lang.String contentEncoding
private boolean chunked
private boolean gzipCompress
public static EntityBuilder create()
private void clearContent()
public java.lang.String getText()
setText(String)
method.public EntityBuilder setText(java.lang.String text)
setBinary(byte[])
,
setStream(java.io.InputStream)
,
setSerializable(java.io.Serializable)
,
setParameters(java.util.List)
,
setParameters(org.apache.http.NameValuePair...)
setFile(java.io.File)
methods.public byte[] getBinary()
setBinary(byte[])
method.public EntityBuilder setBinary(byte[] binary)
setText(String)
,
setStream(java.io.InputStream)
,
setSerializable(java.io.Serializable)
,
setParameters(java.util.List)
,
setParameters(org.apache.http.NameValuePair...)
setFile(java.io.File)
methods.public java.io.InputStream getStream()
InputStream
if set using
setStream(java.io.InputStream)
method.public EntityBuilder setStream(java.io.InputStream stream)
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)
methods.public java.util.List<org.apache.http.NameValuePair> getParameters()
setParameters(java.util.List)
or
setParameters(org.apache.http.NameValuePair...)
methods.public EntityBuilder setParameters(java.util.List<org.apache.http.NameValuePair> parameters)
setText(String)
,
setBinary(byte[])
,
setStream(java.io.InputStream)
,
setSerializable(java.io.Serializable)
,
setFile(java.io.File)
methods.public EntityBuilder setParameters(org.apache.http.NameValuePair... parameters)
setText(String)
,
setBinary(byte[])
,
setStream(java.io.InputStream)
,
setSerializable(java.io.Serializable)
,
setFile(java.io.File)
methods.public java.io.Serializable getSerializable()
Serializable
if set using
setSerializable(java.io.Serializable)
method.public EntityBuilder setSerializable(java.io.Serializable serializable)
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)
methods.public java.io.File getFile()
File
if set using
setFile(java.io.File)
method.public EntityBuilder setFile(java.io.File file)
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)
methods.public org.apache.http.entity.ContentType getContentType()
ContentType
of the entity, if set.public EntityBuilder setContentType(org.apache.http.entity.ContentType contentType)
ContentType
of the entity.public java.lang.String getContentEncoding()
public EntityBuilder setContentEncoding(java.lang.String contentEncoding)
public boolean isChunked()
true
if entity is to be chunk coded, false
otherwise.public EntityBuilder chunked()
public boolean isGzipCompress()
true
if entity is to be GZIP compressed, false
otherwise.public EntityBuilder gzipCompress()
private org.apache.http.entity.ContentType getContentOrDefault(org.apache.http.entity.ContentType def)
public org.apache.http.HttpEntity build()
HttpEntity
based on the current state.