Top Description Fields Constructors Methods
org.apache.hc.core5.http.io.entity

public Class BufferedHttpEntity

extends HttpEntityWrapper
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, org.apache.hc.core5.http.HttpEntity, org.apache.hc.core5.util.Args

A wrapping entity that buffers it content if necessary. The buffered entity is always repeatable. If the wrapped entity is repeatable itself, calls are passed through. If the wrapped entity is not repeatable, the content is read into a buffer once and provided from there as often as required.
Since
4.0

Field Summary

Modifier and TypeField and Description
private final byte[]

Constructor Summary

AccessConstructor and Description
public
BufferedHttpEntity(final HttpEntity
the entity to wrap, not null
entity
)

Creates a new buffered entity wrapper.

Method Summary

Modifier and TypeMethod and Description
public InputStream
public long
public boolean

Returns:

false
isChunked
()

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.isChunked.

Implements org.apache.hc.core5.http.EntityDetails.isChunked.

Tells that this entity does not have to be chunked.
public boolean
public boolean
isStreaming()

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.isStreaming.

Implements org.apache.hc.core5.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream.
public void
writeTo(final OutputStream
the output stream to write entity content to
outStream
)

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.writeTo.

Implements org.apache.hc.core5.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.
Inherited from org.apache.hc.core5.http.io.entity.HttpEntityWrapper:
closegetContentEncodinggetContentTypegetTrailerNamesgetTrailerstoString

Field Detail

bufferback to summary
private final byte[] buffer

Constructor Detail

BufferedHttpEntityback to summary
public BufferedHttpEntity(final HttpEntity entity) throws IOException

Creates a new buffered entity wrapper.

Parameters
entity:HttpEntity

the entity to wrap, not null

Exceptions
IllegalArgumentException:
if wrapped is null

Method Detail

getContentback to summary
public InputStream getContent() throws IOException

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.getContent.

Implements org.apache.hc.core5.http.HttpEntity.getContent.

Doc from org.apache.hc.core5.http.HttpEntity.getContent.

Returns a content stream of the entity. Repeatable entities are expected to create a new instance of InputStream for each invocation of this method and therefore can be consumed multiple times. Entities that are not repeatable are expected to return the same InputStream instance and therefore may not be consumed more than once.

If this entity belongs to an incoming HTTP message, calling InputStream#close() on the returned InputStream will try to consume the complete entity content to keep the connection alive. In cases where this is undesired, e.g. when only a small part of the content is relevant and consuming the complete entity content would be too inefficient, only the HTTP message from which this entity was obtained should be closed (if supported).

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated after the InputStream#close() method is invoked.

Returns:InputStream

content stream of the entity.

Annotations
@Override
Exceptions
IOException:
if the stream could not be created
getContentLengthback to summary
public long getContentLength()

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.getContentLength.

Implements org.apache.hc.core5.http.EntityDetails.getContentLength.

Doc from org.apache.hc.core5.http.EntityDetails.getContentLength.

Returns length of the entity, if known.

Annotations
@Override
isChunkedback to summary
public boolean isChunked()

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.isChunked.

Implements org.apache.hc.core5.http.EntityDetails.isChunked.

Tells that this entity does not have to be chunked.

Returns:boolean

false

Annotations
@Override
isRepeatableback to summary
public boolean isRepeatable()

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.isRepeatable.

Implements org.apache.hc.core5.http.HttpEntity.isRepeatable.

Tells that this entity is repeatable.

Returns:boolean

true

Annotations
@Override
isStreamingback to summary
public boolean isStreaming()

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.isStreaming.

Implements org.apache.hc.core5.http.HttpEntity.isStreaming.

Doc from org.apache.hc.core5.http.HttpEntity.isStreaming.

Tells whether this entity depends on an underlying stream. Streamed entities that read data directly from the socket should return true. Self-contained entities should return false. Wrapping entities should delegate this call to the wrapped entity.

Returns:boolean

true if the entity content is streamed, false otherwise

Annotations
@Override
writeToback to summary
public void writeTo(final OutputStream outStream) throws IOException

Overrides org.apache.hc.core5.http.io.entity.HttpEntityWrapper.writeTo.

Implements org.apache.hc.core5.http.HttpEntity.writeTo.

Doc from org.apache.hc.core5.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated when this method returns.

Parameters
outStream:OutputStream

the output stream to write entity content to

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs