Class EntityBuilder
- java.lang.Object
-
- org.apache.hc.client5.http.entity.EntityBuilder
-
public class EntityBuilder extends java.lang.ObjectBuilder forHttpEntityinstances.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[]binaryprivate booleanchunkedprivate java.lang.StringcontentEncodingprivate org.apache.hc.core5.http.ContentTypecontentTypeprivate java.io.Filefileprivate booleangzipCompressedprivate java.util.List<org.apache.hc.core5.http.NameValuePair>parametersprivate java.io.Serializableserializableprivate java.io.InputStreamstreamprivate java.lang.Stringtext
-
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.HttpEntitybuild()Builds a new instance ofHttpEntitybased on the current state.EntityBuilderchunked()Sets entities to be chunked.private voidclearContent()static EntityBuildercreate()byte[]getBinary()Gets entity content as a byte array if set usingsetBinary(byte[]).java.lang.StringgetContentEncoding()Gets the content encoding of the entity, may be null.private org.apache.hc.core5.http.ContentTypegetContentOrDefault(org.apache.hc.core5.http.ContentType def)org.apache.hc.core5.http.ContentTypegetContentType()Gets theContentTypeof the entity, may be null.java.io.FilegetFile()Gets the entity content as aFileif 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.SerializablegetSerializable()Gets entity content as aSerializableif set usingsetSerializable(java.io.Serializable)method.java.io.InputStreamgetStream()Gets entity content as anInputStreamif set usingsetStream(java.io.InputStream)method.java.lang.StringgetText()Gets the entity content as a string if set usingsetText(String).EntityBuildergzipCompressed()Sets entities to be GZIP compressed.booleanisChunked()Tests if the entity is to be chunk coded (true), or not (false).booleanisGzipCompressed()Tests if entities are to be GZIP compressed (true), or not (false).EntityBuildersetBinary(byte[] binary)Sets entity content as a byte array.EntityBuildersetContentEncoding(java.lang.String contentEncoding)Sets the content encoding of the entity.EntityBuildersetContentType(org.apache.hc.core5.http.ContentType contentType)Sets theContentTypeof the entity.EntityBuildersetFile(java.io.File file)Sets entity content as aFile.EntityBuildersetParameters(java.util.List<org.apache.hc.core5.http.NameValuePair> parameters)Sets entity content as a parameter list.EntityBuildersetParameters(org.apache.hc.core5.http.NameValuePair... parameters)Sets entity content as a parameter list.EntityBuildersetSerializable(java.io.Serializable serializable)Sets entity content as aSerializable.EntityBuildersetStream(java.io.InputStream stream)Sets entity content as anInputStream.EntityBuildersetText(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 anInputStreamif 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 aSerializableif 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 aFileif 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 theContentTypeof the entity, may be null.- Returns:
- the
ContentTypeof the entity, may be null.
-
setContentType
public EntityBuilder setContentType(org.apache.hc.core5.http.ContentType contentType)
Sets theContentTypeof the entity.- Parameters:
contentType- theContentTypeof 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:
trueif entity is to be chunk coded,falseotherwise.
-
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:
trueif entity is to be GZIP compressed,falseotherwise.
-
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 ofHttpEntitybased on the current state.- Returns:
- a new instance.
-
-