Class BasicResource
- All Implemented Interfaces:
- HttpEntity,- HttpResource
- Direct Known Subclasses:
- ByteArrayResource,- FileResource,- ReaderResource,- StreamResource,- StringResource
HttpResource implementation with additional features.
 Provides the following features:
 - Caching.
- Fluent setters.
- Fluent assertions.
- Externally-supplied/dynamic content.
See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionBasicResource(HttpResponse response) Constructor.BasicResource(BasicHttpEntity entity) Constructor.BasicResource(BasicResource copyFrom) Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionAppends the specified header to the end of the headers in this builder.addHeaders(Header... values) Appends the specified headers to the end of the headers in this builder.byte[]asBytes()Converts the contents of the entity of this resource as a byte array.Returns an assertion on the contents of the entity of this resource.protected final voidThrows anUnsupportedOperationExceptionif the unmodifiable flag is set on this bean.Returns an assertion on the contents of the entity of this resource.asString()Converts the contents of the entity of this resource as a string.voidcopy()Creates a builder for this class initialized with the contents of this bean.copyFrom(HttpResponse response) Copies the contents of the specified HTTP response to this builder.longReturns access to the underlying builder for the HTTP entity.Returns the list of headers associated with this resource.booleanbooleanbooleanbooleanReturnstrue 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.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.Sets the specified header in this builder.setHeaders(Header... values) Sets the specified headers in this builder.setHeaders(HeaderList value) Sets the specified headers in this builder.Specifies whether this bean should be unmodifiable.voidwriteTo(OutputStream outStream) 
- 
Constructor Details- 
BasicResourceConstructor.- Parameters:
- entity- The entity that makes up this resource content.
 
- 
BasicResourceCopy constructor.- Parameters:
- copyFrom- The bean bean copied.
 
- 
BasicResourceConstructor.This is the constructor used when parsing an HTTP response. - Parameters:
- response- The HTTP response to copy from. Must not be- null .
- Throws:
- IOException- Rethrown from- HttpEntity.getContent().
 
 
- 
- 
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.
 
- 
copyFromCopies the contents of the specified HTTP response to this builder.- Parameters:
- response- The response to copy from. Must not be null.
- Returns:
- This object.
- Throws:
- IOException- If content could not be retrieved.
 
- 
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.
- 
getEntityReturns access to the underlying builder for the HTTP entity.- Returns:
- The underlying builder for the HTTP entity.
 
- 
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.
 
- 
setHeaderSets the specified header in this builder.This is a no-op if either the name or value is null .- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
addHeaderAppends the specified header to the end of the headers in this builder.This is a no-op if either the name or value is null .- Parameters:
- name- The header name.
- value- The header value.
- Returns:
- This object.
 
- 
setHeadersSets the specified headers in this builder.- Parameters:
- value- The new value.
- Returns:
- This object.
 
- 
setHeadersSets the specified headers in this builder.- Parameters:
- values- The headers to add.- null values are ignored.
- Returns:
- This object.
 
- 
addHeadersAppends the specified headers to the end of the headers in this builder.- Parameters:
- values- The headers to set.- null headers and headers with- null names or values are ignored.
- Returns:
- This object.
 
- 
asStringConverts the contents of the entity of this resource 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 the entity of this resource 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.
 
- 
assertStringReturns an assertion on the contents of the entity of this resource.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 the entity of this resource.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.
 
- 
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
 
- 
getHeadersDescription copied from interface:HttpResourceReturns the list of headers associated with this resource.Note that this typically does NOT include headers associated with HttpEntity(e.g.Content-Type ,Content-Encoding , andContent-Length ).- Specified by:
- getHeadersin interface- HttpResource
- Returns:
- The list of headers associated with this resource.
 
 
-