Class EntityBuilder
- java.lang.Object
-
- org.apache.hc.client5.http.entity.EntityBuilder
-
public class EntityBuilder extends java.lang.Object
Builder forHttpEntity
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
Fields Modifier and Type Field Description private byte[]
binary
private boolean
chunked
private java.lang.String
contentEncoding
private org.apache.hc.core5.http.ContentType
contentType
private java.io.File
file
private boolean
gzipCompressed
private java.util.List<org.apache.hc.core5.http.NameValuePair>
parameters
private java.io.Serializable
serializable
private java.io.InputStream
stream
private java.lang.String
text
-
Constructor Summary
Constructors Constructor Description EntityBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.hc.core5.http.HttpEntity
build()
Builds a new instance ofHttpEntity
based on the current state.EntityBuilder
chunked()
Sets entities to be chunked.private void
clearContent()
static EntityBuilder
create()
byte[]
getBinary()
Gets entity content as a byte array if set usingsetBinary(byte[])
.java.lang.String
getContentEncoding()
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
getContentType()
Gets theContentType
of the entity, may be null.java.io.File
getFile()
Gets the entity content as aFile
if set usingsetFile(java.io.File)
.java.util.List<org.apache.hc.core5.http.NameValuePair>
getParameters()
Gets entity content as a parameter list if set usingsetParameters(java.util.List)
orsetParameters(NameValuePair...)
.java.io.Serializable
getSerializable()
Gets entity content as aSerializable
if set usingsetSerializable(java.io.Serializable)
method.java.io.InputStream
getStream()
Gets entity content as anInputStream
if set usingsetStream(java.io.InputStream)
method.java.lang.String
getText()
Gets the entity content as a string if set usingsetText(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(java.lang.String contentEncoding)
Sets the content encoding of the entity.EntityBuilder
setContentType(org.apache.hc.core5.http.ContentType contentType)
Sets theContentType
of the entity.EntityBuilder
setFile(java.io.File file)
Sets entity content as aFile
.EntityBuilder
setParameters(java.util.List<org.apache.hc.core5.http.NameValuePair> parameters)
Sets entity content as a parameter list.EntityBuilder
setParameters(org.apache.hc.core5.http.NameValuePair... parameters)
Sets entity content as a parameter list.EntityBuilder
setSerializable(java.io.Serializable serializable)
Sets entity content as aSerializable
.EntityBuilder
setStream(java.io.InputStream stream)
Sets entity content as anInputStream
.EntityBuilder
setText(java.lang.String text)
Sets entity content as a string.
-
-
-
Field Detail
-
text
private java.lang.String text
-
binary
private byte[] binary
-
stream
private java.io.InputStream stream
-
parameters
private java.util.List<org.apache.hc.core5.http.NameValuePair> parameters
-
serializable
private java.io.Serializable serializable
-
file
private java.io.File file
-
contentType
private org.apache.hc.core5.http.ContentType contentType
-
contentEncoding
private java.lang.String contentEncoding
-
chunked
private boolean chunked
-
gzipCompressed
private boolean gzipCompressed
-
-
Method Detail
-
create
public static EntityBuilder create()
-
clearContent
private void clearContent()
-
getText
public java.lang.String getText()
Gets the entity content as a string if set usingsetText(String)
.- Returns:
- the entity content as a string, may be null.
-
setText
public EntityBuilder setText(java.lang.String text)
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
public EntityBuilder setBinary(byte[] binary)
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
public java.io.InputStream getStream()
Gets entity content as anInputStream
if set usingsetStream(java.io.InputStream)
method.- Returns:
- entity content as an
InputStream
-
setStream
public EntityBuilder setStream(java.io.InputStream stream)
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
public java.util.List<org.apache.hc.core5.http.NameValuePair> getParameters()
Gets entity content as a parameter list if set usingsetParameters(java.util.List)
orsetParameters(NameValuePair...)
.- Returns:
- entity content as a parameter list.
-
setParameters
public EntityBuilder setParameters(java.util.List<org.apache.hc.core5.http.NameValuePair> parameters)
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
public EntityBuilder setParameters(org.apache.hc.core5.http.NameValuePair... parameters)
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
public java.io.Serializable getSerializable()
Gets entity content as aSerializable
if set usingsetSerializable(java.io.Serializable)
method.- Returns:
- entity content as a
Serializable
.
-
setSerializable
public EntityBuilder setSerializable(java.io.Serializable serializable)
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
public java.io.File getFile()
Gets the entity content as aFile
if set usingsetFile(java.io.File)
.- Returns:
- Gets the entity content as a
File
.
-
setFile
public EntityBuilder setFile(java.io.File file)
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
public EntityBuilder setContentType(org.apache.hc.core5.http.ContentType contentType)
Sets theContentType
of the entity.- Parameters:
contentType
- theContentType
of the entity, may be null.- Returns:
- this
-
getContentEncoding
public java.lang.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(java.lang.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
-
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.
-
-