Package org.apache.juneau.http.entity
Class SerializedEntity
java.lang.Object
org.apache.juneau.http.entity.BasicHttpEntity
org.apache.juneau.http.entity.SerializedEntity
- All Implemented Interfaces:
HttpEntity
HttpEntity for serializing POJOs as the body of HTTP requests.
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.http.entity.BasicHttpEntity
EMPTY
-
Constructor Summary
ConstructorDescriptionConstructor.SerializedEntity
(SerializedEntity copyFrom) Copy constructor.SerializedEntity
(ContentType contentType, Object content, Serializer serializer, HttpPartSchema schema) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a builder for this class initialized with the contents of this bean.copyWith
(Serializer serializer, HttpPartSchema schema) Copies this bean and sets the serializer and schema on it.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.setSchema
(HttpPartSchema value) Sets the schema on this entity bean.setSerializer
(Serializer value) Sets the serializer on this entity bean.Specifies whether this bean should be unmodifiable.void
writeTo
(OutputStream os) Methods inherited from class org.apache.juneau.http.entity.BasicHttpEntity
asBytes, asSafeBytes, assertBytes, assertModifiable, assertString, asString, consumeContent, contentOrElse, getCharset, getContentEncoding, getMaxLength, isCached, isChunked, isStreaming, isSupplied, isUnmodifiable
-
Constructor Details
-
SerializedEntity
public SerializedEntity()Constructor. -
SerializedEntity
public SerializedEntity(ContentType contentType, Object content, Serializer serializer, HttpPartSchema schema) Constructor.- Parameters:
contentType
- The entity content type.content
- The entity content.serializer
- The entity serializer.schema
- The entity schema. Can benull .
-
SerializedEntity
Copy constructor.- Parameters:
copyFrom
- The bean being copied.
-
-
Method Details
-
copy
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.
-
copyWith
Copies this bean and sets the serializer and schema on it.- Parameters:
serializer
- The new serializer for the bean. Can benull .schema
- The new schema for the bean. Can benull .- Returns:
- Either a new bean with the serializer set, or this bean if
both values are
null or the serializer and schema were already set.
-
setSerializer
Sets the serializer on this entity bean.- Parameters:
value
- The entity serializer, can benull .- Returns:
- This object.
-
setSchema
Sets the schema on this entity bean.Used to provide instructions to the serializer on how to serialize this object.
- Parameters:
value
- The entity schema, can benull .- Returns:
- This object.
-
getContentType
- Specified by:
getContentType
in interfaceHttpEntity
- Overrides:
getContentType
in classBasicHttpEntity
-
writeTo
- Specified by:
writeTo
in interfaceHttpEntity
- Overrides:
writeTo
in classBasicHttpEntity
- Throws:
IOException
-
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
-
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.
-