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

public Class BasicHttpEntity

extends AbstractHttpEntity
Class Inheritance
Annotations
@Contract
threading:IMMUTABLE_CONDITIONAL
Imports
java.io.IOException, .InputStream, org.apache.hc.core5.annotation.Contract, .ThreadingBehavior, org.apache.hc.core5.http.ContentType, org.apache.hc.core5.io.Closer, org.apache.hc.core5.util.Args

A generic streamed, non-repeatable entity that obtains its content from an InputStream.
Since
4.0

Field Summary

Modifier and TypeField and Description
private final InputStream
private final long
Inherited from org.apache.hc.core5.http.io.entity.AbstractHttpEntity:
OUTPUT_BUFFER_SIZE

Constructor Summary

AccessConstructor and Description
public
BasicHttpEntity(final InputStream content, final long length, final ContentType contentType, final String contentEncoding, final boolean chunked)

public
BasicHttpEntity(final InputStream content, final long length, final ContentType contentType, final String contentEncoding)

public
BasicHttpEntity(final InputStream content, final long length, final ContentType contentType)

public
BasicHttpEntity(final InputStream content, final ContentType contentType, final String contentEncoding)

public
BasicHttpEntity(final InputStream content, final ContentType contentType)

public
BasicHttpEntity(final InputStream content, final ContentType contentType, final boolean chunked)

Method Summary

Modifier and TypeMethod and Description
public final void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public final InputStream
getContent()

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

Returns a content stream of the entity.
public final long
getContentLength()

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

Returns length of the entity, if known.
public final boolean
isRepeatable()

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

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

Tells if the entity is capable of producing its data more than once.
public final boolean
isStreaming()

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

Tells whether this entity depends on an underlying stream.
Inherited from org.apache.hc.core5.http.io.entity.AbstractHttpEntity:
getContentEncodinggetContentTypegetTrailerNamesgetTrailersisChunkedtoStringwriteTowriteTo

Field Detail

contentback to summary
private final InputStream content
lengthback to summary
private final long length

Constructor Detail

BasicHttpEntityback to summary
public BasicHttpEntity(final InputStream content, final long length, final ContentType contentType, final String contentEncoding, final boolean chunked)
BasicHttpEntityback to summary
public BasicHttpEntity(final InputStream content, final long length, final ContentType contentType, final String contentEncoding)
BasicHttpEntityback to summary
public BasicHttpEntity(final InputStream content, final long length, final ContentType contentType)
BasicHttpEntityback to summary
public BasicHttpEntity(final InputStream content, final ContentType contentType, final String contentEncoding)
BasicHttpEntityback to summary
public BasicHttpEntity(final InputStream content, final ContentType contentType)
BasicHttpEntityback to summary
public BasicHttpEntity(final InputStream content, final ContentType contentType, final boolean chunked)

Method Detail

closeback to summary
public final void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
getContentback to summary
public final InputStream getContent() throws IllegalStateException

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
getContentLengthback to summary
public final long 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
isRepeatableback to summary
public final boolean isRepeatable()

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

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

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

Tells if the entity is capable of producing its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.

Returns:boolean

true if the entity is repeatable, false otherwise.

Annotations
@Override
isStreamingback to summary
public final boolean 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