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 ContentCodingcompressWithThe compression algorithm to apply whenbuildingthe finalHttpEntity.private java.lang.StringcontentEncodingprivate org.apache.hc.core5.http.ContentTypecontentTypeprivate java.io.Filefileprivate booleangzipCompressedDeprecated.usecompressWithinsteadprivate 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 Deprecated 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()EntityBuildercompressed(ContentCoding coding)Requests that the entity produced by this builder be compressed with the supplied content-coding.static EntityBuildercreate()byte[]getBinary()Gets entity content as a byte array if set usingsetBinary(byte[]).ContentCodinggetCompressWith()Returns the content-coding thatbuild()will apply to the outgoingHttpEntity, ornullwhen no compression has been requested.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()Deprecated.since 5.6 – replace withcompressed(ContentCoding.GZIP).booleanisChunked()Tests if the entity is to be chunk coded (true), or not (false).booleanisGzipCompressed()Deprecated.since 5.6 – usegetCompressWith()and check forContentCoding.GZIPinstead.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
@Deprecated private boolean gzipCompressed
Deprecated.usecompressWithinstead
-
compressWith
private ContentCoding compressWith
The compression algorithm to apply whenbuildingthe finalHttpEntity.If
null(default) the entity is sent as-is; otherwise the entity content is wrapped in the corresponding compressing wrapper (for exampleGzipCompressingEntity,DeflateCompressingEntity, or a Commons-Compress based implementation) and the correctContent-Encodingheader is added.- Since:
- 5.6
-
-
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 instance.
-
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 instance.
-
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 instance.
-
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 instance.
-
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 instance.
-
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 instance.
-
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 instance.
-
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 instance.
-
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 instance.
-
isGzipCompressed
@Deprecated public boolean isGzipCompressed()
Deprecated.since 5.6 – usegetCompressWith()and check forContentCoding.GZIPinstead.Tests if entities are to be GZIP compressed (true), or not (false).- Returns:
trueif entity is to be GZIP compressed,falseotherwise.
-
gzipCompressed
@Deprecated public EntityBuilder gzipCompressed()
Deprecated.since 5.6 – replace withcompressed(ContentCoding.GZIP).Sets entities to be GZIP compressed.- Returns:
- this instance.
-
compressed
public EntityBuilder compressed(ContentCoding coding)
Requests that the entity produced by this builder be compressed with the supplied content-coding.- Parameters:
coding- the content-coding to use (nevernull)- Returns:
- this builder for method chaining
- Since:
- 5.6
-
getCompressWith
public ContentCoding getCompressWith()
Returns the content-coding thatbuild()will apply to the outgoingHttpEntity, ornullwhen no compression has been requested.- Returns:
- the chosen
ContentCoding— typicallyContentCoding.GZIP,ContentCoding.DEFLATE, etc. — ornullif the request body will be sent uncompressed. - Since:
- 5.6
-
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.
-
-