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

public Class PathEntity

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

A self contained, repeatable entity that obtains its content from a path.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
PathEntity(final Path path, final ContentType contentType, final String contentEncoding)

public
PathEntity(final Path path, final ContentType contentType)

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

pathback to summary
private final Path path

Constructor Detail

PathEntityback to summary
public PathEntity(final Path path, final ContentType contentType, final String contentEncoding)
PathEntityback to summary
public PathEntity(final Path path, final ContentType contentType)

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 IOException

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 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