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 booleanprivate ContentCodingThe compression algorithm to apply whenbuildingthe finalHttpEntity.private Stringprivate org.apache.hc.core5.http.ContentTypeprivate Fileprivate booleanDeprecated.private List<org.apache.hc.core5.http.NameValuePair> private Serializableprivate InputStreamprivate String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.hc.core5.http.HttpEntitybuild()Builds a new instance ofHttpEntitybased on the current state.chunked()Sets entities to be chunked.private voidcompressed(ContentCoding coding) Requests that the entity produced by this builder be compressed with the supplied content-coding.static EntityBuildercreate()byte[]Gets entity content as a byte array if set usingsetBinary(byte[]).Returns the content-coding thatbuild()will apply to the outgoingHttpEntity, ornullwhen no compression has been requested.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.ContentTypeGets theContentTypeof the entity, may be null.getFile()Gets the entity content as aFileif 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 aSerializableif set usingsetSerializable(java.io.Serializable)method.Gets entity content as anInputStreamif set usingsetStream(java.io.InputStream)method.getText()Gets the entity content as a string if set usingsetText(String).Deprecated.since 5.6 – replace withcompressed(ContentCoding.GZIP).booleanTests if the entity is to be chunk coded (true), or not (false).booleanDeprecated.since 5.6 – usegetCompressWith()and check forContentCoding.GZIPinstead.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 theContentTypeof 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
Deprecated.usecompressWithinstead -
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
-
-
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 instance.
-
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 instance.
-
getStream
Gets entity content as anInputStreamif 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 instance.
-
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 instance.
-
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 aSerializableif 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 instance.
-
getFile
Gets the entity content as aFileif 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 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
Sets theContentTypeof the entity.- Parameters:
contentType- theContentTypeof the entity, may be null.- Returns:
- this instance.
-
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 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
-
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.since 5.6 – replace withcompressed(ContentCoding.GZIP).Sets entities to be GZIP compressed.- Returns:
- this instance.
-
compressed
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
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.
-
compressWithinstead