Package org.apache.juneau.http.entity
Class BasicHttpEntity
java.lang.Object
org.apache.juneau.http.entity.BasicHttpEntity
- All Implemented Interfaces:
- HttpEntity
- Direct Known Subclasses:
- ByteArrayEntity,- FileEntity,- ReaderEntity,- SerializedEntity,- StreamEntity,- StringEntity
A basic 
HttpEntity implementation with additional features.
 Provides the following features:
 - Caching.
- Fluent setters.
- Fluent assertions.
- Externally-supplied/dynamic content.
See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor.BasicHttpEntity(BasicHttpEntity copyFrom) Copy constructor.BasicHttpEntity(ContentType contentType, Object content) Constructor.
- 
Method SummaryModifier and TypeMethodDescriptionbyte[]asBytes()Converts the contents of this entity as a byte array.protected byte[]Returns an assertion on the contents of this entity.protected final voidThrows anUnsupportedOperationExceptionif the unmodifiable flag is set on this bean.Returns an assertion on the contents of this entity.asString()Converts the contents of this entity as a string.voidprotected <T> TcontentOrElse(T def) Returns the content of this entity.copy()Creates a builder for this class initialized with the contents of this bean.Returns the charset to use when converting to and from stream-based resources.longintReturns the maximum number of bytes to read or write to and from stream-based resources.booleanisCached()Returnstrue if this entity is cached in-memory.booleanbooleanbooleanprotected booleanReturnstrue if the contents of this entity are provided through an external supplier.booleanReturnstrue if this bean is unmodifiable.Specifies that the contents of this resource should be cached into an internal byte array so that it can be read multiple times.setCharset(Charset value) Specifies the charset to use when converting to and from stream-based resources.Sets the 'chunked' flag value totrue .setChunked(boolean value) Sets the 'chunked' flag value.setContent(Object value) Sets the content on this entity bean.setContent(Supplier<?> value) Sets the content on this entity bean from a supplier.setContentEncoding(String value) Sets the content encoding header on this entity bean.Sets the content encoding header on this entity bean.setContentLength(long value) Sets the content length on this entity bean.setContentType(String value) Sets the content type on this entity bean.setContentType(ContentType value) Sets the content type on this entity bean.setMaxLength(int value) Specifies the maximum number of bytes to read or write to and from stream-based resources.Specifies whether this bean should be unmodifiable.voidwriteTo(OutputStream outStream) 
- 
Field Details- 
EMPTYAn empty HttpEntity.
 
- 
- 
Constructor Details- 
BasicHttpEntitypublic BasicHttpEntity()Constructor.
- 
BasicHttpEntityConstructor.- Parameters:
- contentType- The entity content type.
- content- The entity content.
 
- 
BasicHttpEntityCopy constructor.- Parameters:
- copyFrom- The bean being copied.
 
 
- 
- 
Method Details- 
copyCreates a builder for this class initialized with the contents of this bean.Allows you to create a modifiable copy of this bean. - Returns:
- A new builder bean.
 
- 
setUnmodifiableSpecifies whether this bean should be unmodifiable.When enabled, attempting to set any properties on this bean will cause an UnsupportedOperationException.- Returns:
- This object.
 
- 
isUnmodifiableReturnstrue if this bean is unmodifiable.- Returns:
- true if this bean is unmodifiable.
 
- 
assertModifiableThrows anUnsupportedOperationExceptionif the unmodifiable flag is set on this bean.
- 
setContentSets the content on this entity bean.- Parameters:
- value- The entity content, can be- null .
- Returns:
- This object.
 
- 
setContentSets the content on this entity bean from a supplier.Repeatable entities such as StringEntityuse this to allow the entity content to be resolved at serialization time.- Parameters:
- value- The entity content, can be- null .
- Returns:
- This object.
 
- 
setContentTypeSets the content type on this entity bean.- Parameters:
- value- The new- Content-Type header, or- null to unset.
- Returns:
- This object.
 
- 
setContentTypeSets the content type on this entity bean.- Parameters:
- value- The new- Content-Type header, or- null to unset.
- Returns:
- This object.
 
- 
setContentLengthSets the content length on this entity bean.- Parameters:
- value- The new- Content-Length header value, or- -1 to unset.
- Returns:
- This object.
 
- 
setContentEncodingSets the content encoding header on this entity bean.- Parameters:
- value- The new- Content-Encoding header, or- null to unset.
- Returns:
- This object.
 
- 
setContentEncodingSets the content encoding header on this entity bean.- Parameters:
- value- The new- Content-Encoding header, or- null to unset.
- Returns:
- This object.
 
- 
setChunkedSets the 'chunked' flag value totrue .Notes:- If the HttpEntity.getContentLength()method returns a negative value, the HttpClient code will always use chunked encoding.
 - Returns:
- This object.
 
- If the 
- 
setChunkedSets the 'chunked' flag value.Notes:- If the HttpEntity.getContentLength()method returns a negative value, the HttpClient code will always use chunked encoding.
 - Parameters:
- value- The new value for this flag.
- Returns:
- This object.
 
- If the 
- 
setCachedSpecifies that the contents of this resource should be cached into an internal byte array so that it can be read multiple times.- Returns:
- This object.
- Throws:
- IOException- If entity could not be read into memory.
 
- 
isCachedReturnstrue if this entity is cached in-memory.- Returns:
- true if this entity is cached in-memory.
 
- 
setCharsetSpecifies the charset to use when converting to and from stream-based resources.- Parameters:
- value- The new value. If- null ,- UTF-8 is assumed.
- Returns:
- This object.
 
- 
getCharsetReturns the charset to use when converting to and from stream-based resources.- Returns:
- The charset to use when converting to and from stream-based resources.
 
- 
setMaxLengthSpecifies the maximum number of bytes to read or write to and from stream-based resources.Implementation is not universal. - Parameters:
- value- The new value. The default is- -1 which means read everything.
- Returns:
- This object.
 
- 
getMaxLengthReturns the maximum number of bytes to read or write to and from stream-based resources.- Returns:
- The maximum number of bytes to read or write to and from stream-based resources.
 
- 
asStringConverts the contents of this entity as a string.Note that this may exhaust the content on non-repeatable, non-cached entities. - Returns:
- The contents of this entity as a string.
- Throws:
- IOException- If a problem occurred while trying to read the content.
 
- 
asBytesConverts the contents of this entity as a byte array.Note that this may exhaust the content on non-repeatable, non-cached entities. - Returns:
- The contents of this entity as a byte array.
- Throws:
- IOException- If a problem occurred while trying to read the content.
 
- 
asSafeBytes- Returns:
- The contents of this entity as a byte array.
 
- 
assertStringReturns an assertion on the contents of this entity.Note that this may exhaust the content on non-repeatable, non-cached entities. - Returns:
- A new fluent assertion.
- Throws:
- IOException- If a problem occurred while trying to read the byte array.
 
- 
assertBytesReturns an assertion on the contents of this entity.Note that this may exhaust the content on non-repeatable, non-cached entities. - Returns:
- A new fluent assertion.
- Throws:
- IOException- If a problem occurred while trying to read the byte array.
 
- 
contentOrElseReturns the content of this entity.- Type Parameters:
- T- The value type.
- Parameters:
- def- The default value if- null .
- Returns:
- The content object.
 
- 
isSuppliedReturnstrue if the contents of this entity are provided through an external supplier.Externally supplied content generally means the content length cannot be reliably determined based on the content. - Returns:
- true if the contents of this entity are provided through an external supplier.
 
- 
getContentLength- Specified by:
- getContentLengthin interface- HttpEntity
 
- 
isRepeatable- Specified by:
- isRepeatablein interface- HttpEntity
 
- 
isChunked- Specified by:
- isChunkedin interface- HttpEntity
 
- 
getContentType- Specified by:
- getContentTypein interface- HttpEntity
 
- 
getContentEncoding- Specified by:
- getContentEncodingin interface- HttpEntity
 
- 
isStreaming- Specified by:
- isStreamingin interface- HttpEntity
 
- 
consumeContent- Specified by:
- consumeContentin interface- HttpEntity
- Throws:
- IOException
 
- 
getContent- Specified by:
- getContentin interface- HttpEntity
- Throws:
- IOException
- UnsupportedOperationException
 
- 
writeTo- Specified by:
- writeToin interface- HttpEntity
- Throws:
- IOException
 
 
-