Class EntityBuilder
java.lang.Object
org.apache.hc.client5.http.entity.EntityBuilder
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
FieldsModifier and TypeFieldDescriptionprivate byte[]
private boolean
private String
private org.apache.hc.core5.http.ContentType
private File
private boolean
private List
<org.apache.hc.core5.http.NameValuePair> private Serializable
private InputStream
private String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.hc.core5.http.HttpEntity
build()
Builds a new instance ofHttpEntity
based on the current state.chunked()
Sets entities to be chunked.private void
static EntityBuilder
create()
byte[]
Gets entity content as a byte array if set usingsetBinary(byte[])
.Gets the content encoding of the entity, may be null.private org.apache.hc.core5.http.ContentType
getContentOrDefault
(org.apache.hc.core5.http.ContentType def) org.apache.hc.core5.http.ContentType
Gets theContentType
of the entity, may be null.getFile()
Gets the entity content as aFile
if set usingsetFile(java.io.File)
.List
<org.apache.hc.core5.http.NameValuePair> Gets entity content as a parameter list if set usingsetParameters(java.util.List)
orsetParameters(NameValuePair...)
.Gets entity content as aSerializable
if set usingsetSerializable(java.io.Serializable)
method.Gets entity content as anInputStream
if set usingsetStream(java.io.InputStream)
method.getText()
Gets the entity content as a string if set usingsetText(String)
.Sets entities to be GZIP compressed.boolean
Tests if the entity is to be chunk coded (true
), or not (false
).boolean
Tests if entities are to be GZIP compressed (true
), or not (false
).setBinary
(byte[] binary) Sets entity content as a byte array.setContentEncoding
(String contentEncoding) Sets the content encoding of the entity.setContentType
(org.apache.hc.core5.http.ContentType contentType) Sets theContentType
of the entity.Sets entity content as aFile
.setParameters
(List<org.apache.hc.core5.http.NameValuePair> parameters) Sets entity content as a parameter list.setParameters
(org.apache.hc.core5.http.NameValuePair... parameters) Sets entity content as a parameter list.setSerializable
(Serializable serializable) Sets entity content as aSerializable
.setStream
(InputStream stream) Sets entity content as anInputStream
.Sets entity content as a string.
-
Field Details
-
text
-
binary
private byte[] binary -
stream
-
parameters
-
serializable
-
file
-
contentType
private org.apache.hc.core5.http.ContentType contentType -
contentEncoding
-
chunked
private boolean chunked -
gzipCompressed
private boolean gzipCompressed
-
-
Constructor Details
-
EntityBuilder
EntityBuilder()
-
-
Method Details
-
create
-
clearContent
private void clearContent() -
getText
Gets the entity content as a string if set usingsetText(String)
.- Returns:
- the entity content as a string, may be null.
-
setText
Sets entity content as a string. This method is mutually exclusive withsetBinary(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 usingsetBinary(byte[])
.- Returns:
- entity content as a byte array.
-
setBinary
Sets entity content as a byte array. This method is mutually exclusive withsetText(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
Gets entity content as anInputStream
if set usingsetStream(java.io.InputStream)
method.- Returns:
- entity content as an
InputStream
-
setStream
Sets entity content as anInputStream
. This method is mutually exclusive withsetText(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
Gets entity content as a parameter list if set usingsetParameters(java.util.List)
orsetParameters(NameValuePair...)
.- Returns:
- entity content as a parameter list.
-
setParameters
Sets entity content as a parameter list. This method is mutually exclusive withsetText(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
Sets entity content as a parameter list. This method is mutually exclusive withsetText(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
Gets entity content as aSerializable
if set usingsetSerializable(java.io.Serializable)
method.- Returns:
- entity content as a
Serializable
.
-
setSerializable
Sets entity content as aSerializable
. This method is mutually exclusive withsetText(String)
,setBinary(byte[])
,setStream(java.io.InputStream)
,setParameters(java.util.List)
,setParameters(NameValuePair...)
setFile(java.io.File)
.- Parameters:
serializable
- entity content as aSerializable
.- Returns:
- this
-
getFile
Gets the entity content as aFile
if set usingsetFile(java.io.File)
.- Returns:
- Gets the entity content as a
File
.
-
setFile
Sets entity content as aFile
. This method is mutually exclusive withsetText(String)
,setBinary(byte[])
,setStream(java.io.InputStream)
,setParameters(java.util.List)
,setParameters(NameValuePair...)
setSerializable(java.io.Serializable)
.- Parameters:
file
- entity content as aFile
.- Returns:
- this
-
getContentType
public org.apache.hc.core5.http.ContentType getContentType()Gets theContentType
of the entity, may be null.- Returns:
- the
ContentType
of the entity, may be null.
-
setContentType
Sets theContentType
of the entity.- Parameters:
contentType
- theContentType
of the entity, may be null.- Returns:
- this
-
getContentEncoding
Gets the content encoding of the entity, may be null.- Returns:
- the content encoding of the entity, may be null.
-
setContentEncoding
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
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
Sets entities to be GZIP compressed.- Returns:
- this
-
getContentOrDefault
private org.apache.hc.core5.http.ContentType getContentOrDefault(org.apache.hc.core5.http.ContentType def) -
build
public org.apache.hc.core5.http.HttpEntity build()Builds a new instance ofHttpEntity
based on the current state.- Returns:
- a new instance.
-