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
ConstructorsModifierConstructorDescriptionConstructor.protectedByteArrayEntity(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.longbooleanSpecifies 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 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
-
asBytes
Description copied from class:BasicHttpEntityConverts the contents of this entity as a byte array.Note that this may exhaust the content on non-repeatable, non-cached entities.
- Overrides:
asBytesin classBasicHttpEntity- Returns:
- The contents of this entity as a byte array.
- Throws:
IOException- If a problem occurred while trying to read the content.
-
asString
Description copied from class:BasicHttpEntityConverts the contents of this entity as a string.Note that this may exhaust the content on non-repeatable, non-cached entities.
- Overrides:
asStringin classBasicHttpEntity- Returns:
- The contents of this entity as a string.
- Throws:
IOException- If a problem occurred while trying to read the content.
-
copy
Description copied from class:BasicHttpEntityCreates a builder for this class initialized with the contents of this bean.Allows you to create a modifiable copy of this bean.
- Overrides:
copyin classBasicHttpEntity- Returns:
- A new builder bean.
-
getContent
- Specified by:
getContentin interfaceHttpEntity- Overrides:
getContentin classBasicHttpEntity- Throws:
IOException
-
getContentLength
- Specified by:
getContentLengthin interfaceHttpEntity- Overrides:
getContentLengthin classBasicHttpEntity
-
isRepeatable
- Specified by:
isRepeatablein interfaceHttpEntity- Overrides:
isRepeatablein classBasicHttpEntity
-
setCached
Description copied from class:BasicHttpEntitySpecifies that the contents of this resource should be cached into an internal byte array so that it can be read multiple times.- Overrides:
setCachedin classBasicHttpEntity- Returns:
- This object.
- Throws:
IOException- If entity could not be read into memory.
-
setCharset
Description copied from class:BasicHttpEntitySpecifies the charset to use when converting to and from stream-based resources.- Overrides:
setCharsetin classBasicHttpEntity- Parameters:
value- The new value. Ifnull ,UTF-8 is assumed.- Returns:
- This object.
-
setChunked
Description copied from class:BasicHttpEntitySets the 'chunked' flag value totrue .Notes:
- If the
HttpEntity.getContentLength()method returns a negative value, the HttpClient code will always use chunked encoding.
- Overrides:
setChunkedin classBasicHttpEntity- Returns:
- This object.
- If the
-
setChunked
Description copied from class:BasicHttpEntitySets the 'chunked' flag value.Notes:
- If the
HttpEntity.getContentLength()method returns a negative value, the HttpClient code will always use chunked encoding.
- Overrides:
setChunkedin classBasicHttpEntity- Parameters:
value- The new value for this flag.- Returns:
- This object.
- If the
-
setContent
Description copied from class:BasicHttpEntitySets the content on this entity bean.- Overrides:
setContentin classBasicHttpEntity- Parameters:
value- The entity content, can benull .- Returns:
- This object.
-
setContent
Description copied from class:BasicHttpEntitySets 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.- Overrides:
setContentin classBasicHttpEntity- Parameters:
value- The entity content, can benull .- Returns:
- This object.
-
setContentEncoding
Description copied from class:BasicHttpEntitySets the content encoding header on this entity bean.- Overrides:
setContentEncodingin classBasicHttpEntity- Parameters:
value- The newContent-Encoding header, ornull to unset.- Returns:
- This object.
-
setContentEncoding
Description copied from class:BasicHttpEntitySets the content encoding header on this entity bean.- Overrides:
setContentEncodingin classBasicHttpEntity- Parameters:
value- The newContent-Encoding header, ornull to unset.- Returns:
- This object.
-
setContentLength
Description copied from class:BasicHttpEntitySets the content length on this entity bean.- Overrides:
setContentLengthin classBasicHttpEntity- Parameters:
value- The newContent-Length header value, or-1 to unset.- Returns:
- This object.
-
setContentType
Description copied from class:BasicHttpEntitySets the content type on this entity bean.- Overrides:
setContentTypein classBasicHttpEntity- Parameters:
value- The newContent-Type header, ornull to unset.- Returns:
- This object.
-
setContentType
Description copied from class:BasicHttpEntitySets the content type on this entity bean.- Overrides:
setContentTypein classBasicHttpEntity- Parameters:
value- The newContent-Type header, ornull to unset.- Returns:
- This object.
-
setMaxLength
Description copied from class:BasicHttpEntitySpecifies the maximum number of bytes to read or write to and from stream-based resources.Implementation is not universal.
- Overrides:
setMaxLengthin classBasicHttpEntity- Parameters:
value- The new value. The default is-1 which means read everything.- Returns:
- This object.
-
setUnmodifiable
Description copied from class:BasicHttpEntitySpecifies whether this bean should be unmodifiable.When enabled, attempting to set any properties on this bean will cause an
UnsupportedOperationException.- Overrides:
setUnmodifiablein classBasicHttpEntity- Returns:
- This object.
-
writeTo
- Specified by:
writeToin interfaceHttpEntity- Overrides:
writeToin classBasicHttpEntity- Throws:
IOException
-