Package org.apache.juneau.http.entity
Class ByteArrayEntity
java.lang.Object
org.apache.juneau.http.entity.BasicHttpEntity
org.apache.juneau.http.entity.ByteArrayEntity
- All Implemented Interfaces:
HttpEntity
A repeatable entity that obtains its content from a byte array.
See Also:
-
Constructor Summary
ModifierConstructorDescriptionConstructor.protected
ByteArrayEntity
(ByteArrayEntity copyFrom) Copy constructor.ByteArrayEntity
(ContentType contentType, byte[] contents) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
asBytes()
Converts the contents of this entity as a byte array.asString()
Converts the contents of this entity as a string.copy()
Creates a builder for this class initialized with the contents of this bean.long
boolean
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.void
writeTo
(OutputStream out) Methods inherited from class org.apache.juneau.http.entity.BasicHttpEntity
asSafeBytes, assertBytes, assertModifiable, assertString, consumeContent, contentOrElse, getCharset, getContentEncoding, getContentType, getMaxLength, isCached, isChunked, isStreaming, isSupplied, isUnmodifiable
-
Constructor Details
-
ByteArrayEntity
public ByteArrayEntity()Constructor. -
ByteArrayEntity
Constructor.- Parameters:
contentType
- The entity content type.contents
- The entity contents.
-
ByteArrayEntity
Copy constructor.- Parameters:
copyFrom
- The bean being copied.
-
-
Method Details
-
copy
Description copied from class:BasicHttpEntity
Creates a builder for this class initialized with the contents of this bean.Allows you to create a modifiable copy of this bean.
- Overrides:
copy
in classBasicHttpEntity
- Returns:
- A new builder bean.
-
asString
Description copied from class:BasicHttpEntity
Converts the contents of this entity as a string.Note that this may exhaust the content on non-repeatable, non-cached entities.
- Overrides:
asString
in classBasicHttpEntity
- Returns:
- The contents of this entity as a string.
- Throws:
IOException
- If a problem occurred while trying to read the content.
-
asBytes
Description copied from class:BasicHttpEntity
Converts the contents of this entity as a byte array.Note that this may exhaust the content on non-repeatable, non-cached entities.
- Overrides:
asBytes
in classBasicHttpEntity
- Returns:
- The contents of this entity as a byte array.
- Throws:
IOException
- If a problem occurred while trying to read the content.
-
isRepeatable
- Specified by:
isRepeatable
in interfaceHttpEntity
- Overrides:
isRepeatable
in classBasicHttpEntity
-
getContentLength
- Specified by:
getContentLength
in interfaceHttpEntity
- Overrides:
getContentLength
in classBasicHttpEntity
-
getContent
- Specified by:
getContent
in interfaceHttpEntity
- Overrides:
getContent
in classBasicHttpEntity
- Throws:
IOException
-
writeTo
- Specified by:
writeTo
in interfaceHttpEntity
- Overrides:
writeTo
in classBasicHttpEntity
- Throws:
IOException
-
setCached
Description copied from class:BasicHttpEntity
Specifies that the contents of this resource should be cached into an internal byte array so that it can be read multiple times.- Overrides:
setCached
in classBasicHttpEntity
- Returns:
- This object.
- Throws:
IOException
- If entity could not be read into memory.
-
setCharset
Description copied from class:BasicHttpEntity
Specifies the charset to use when converting to and from stream-based resources.- Overrides:
setCharset
in classBasicHttpEntity
- Parameters:
value
- The new value. Ifnull ,UTF-8 is assumed.- Returns:
- This object.
-
setChunked
Description copied from class:BasicHttpEntity
Sets the 'chunked' flag value totrue .Notes:
- If the
HttpEntity.getContentLength()
method returns a negative value, the HttpClient code will always use chunked encoding.
- Overrides:
setChunked
in classBasicHttpEntity
- Returns:
- This object.
- If the
-
setChunked
Description copied from class:BasicHttpEntity
Sets the 'chunked' flag value.Notes:
- If the
HttpEntity.getContentLength()
method returns a negative value, the HttpClient code will always use chunked encoding.
- Overrides:
setChunked
in classBasicHttpEntity
- Parameters:
value
- The new value for this flag.- Returns:
- This object.
- If the
-
setContent
Description copied from class:BasicHttpEntity
Sets the content on this entity bean.- Overrides:
setContent
in classBasicHttpEntity
- Parameters:
value
- The entity content, can benull .- Returns:
- This object.
-
setContent
Description copied from class:BasicHttpEntity
Sets the content on this entity bean from a supplier.Repeatable entities such as
StringEntity
use this to allow the entity content to be resolved at serialization time.- Overrides:
setContent
in classBasicHttpEntity
- Parameters:
value
- The entity content, can benull .- Returns:
- This object.
-
setContentEncoding
Description copied from class:BasicHttpEntity
Sets the content encoding header on this entity bean.- Overrides:
setContentEncoding
in classBasicHttpEntity
- Parameters:
value
- The newContent-Encoding header, ornull to unset.- Returns:
- This object.
-
setContentEncoding
Description copied from class:BasicHttpEntity
Sets the content encoding header on this entity bean.- Overrides:
setContentEncoding
in classBasicHttpEntity
- Parameters:
value
- The newContent-Encoding header, ornull to unset.- Returns:
- This object.
-
setContentLength
Description copied from class:BasicHttpEntity
Sets the content length on this entity bean.- Overrides:
setContentLength
in classBasicHttpEntity
- Parameters:
value
- The newContent-Length header value, or-1 to unset.- Returns:
- This object.
-
setContentType
Description copied from class:BasicHttpEntity
Sets the content type on this entity bean.- Overrides:
setContentType
in classBasicHttpEntity
- Parameters:
value
- The newContent-Type header, ornull to unset.- Returns:
- This object.
-
setContentType
Description copied from class:BasicHttpEntity
Sets the content type on this entity bean.- Overrides:
setContentType
in classBasicHttpEntity
- Parameters:
value
- The newContent-Type header, ornull to unset.- Returns:
- This object.
-
setMaxLength
Description copied from class:BasicHttpEntity
Specifies the maximum number of bytes to read or write to and from stream-based resources.Implementation is not universal.
- Overrides:
setMaxLength
in classBasicHttpEntity
- Parameters:
value
- The new value. The default is-1 which means read everything.- Returns:
- This object.
-
setUnmodifiable
Description copied from class:BasicHttpEntity
Specifies whether this bean should be unmodifiable.When enabled, attempting to set any properties on this bean will cause an
UnsupportedOperationException
.- Overrides:
setUnmodifiable
in classBasicHttpEntity
- Returns:
- This object.
-