Top Description Fields Constructors Methods
org.apache.hc.core5.http.impl.nio

public Class LengthDelimitedDecoder

extends AbstractContentDecoder
implements FileContentDecoder
Class Inheritance
All Implemented Interfaces
org.apache.hc.core5.http.nio.FileContentDecoder, org.apache.hc.core5.http.nio.ContentDecoder
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, .ReadableByteChannel, org.apache.hc.core5.http.ConnectionClosedException, org.apache.hc.core5.http.impl.BasicHttpTransportMetrics, org.apache.hc.core5.http.nio.FileContentDecoder, .SessionInputBuffer, org.apache.hc.core5.util.Args

Content decoder that cuts off after a defined number of bytes. This class is used to receive content of HTTP messages where the end of the content entity is determined by the value of the Content-Length header. Entities transferred using this stream can be maximum Long#MAX_VALUE long.

This decoder is optimized to transfer data directly from the underlying I/O session's channel to a FileChannel, whenever possible avoiding intermediate buffering in the session buffer.

Since
4.0

Field Summary

Modifier and TypeField and Description
private final long
private long
Inherited from org.apache.hc.core5.http.impl.nio.AbstractContentDecoder:
bufferchannelcompletedmetrics

Constructor Summary

AccessConstructor and Description
public
LengthDelimitedDecoder(final ReadableByteChannel channel, final SessionInputBuffer buffer, final BasicHttpTransportMetrics metrics, final long contentLength)

Method Summary

Modifier and TypeMethod and Description
public int
read(final ByteBuffer
The buffer into which entity content is to be transferred
dst
)

Implements org.apache.hc.core5.http.nio.ContentDecoder.read.

Reads a portion of content from the underlying channel
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public long
transfer(final FileChannel
the target FileChannel to transfer data into.
dst
,
final long
The position within the file at which the transfer is to begin; must be non-negative. Must be less than or equal to the size of the file
position
,
final long
The maximum number of bytes to be transferred; must be non-negative
count
)

Implements org.apache.hc.core5.http.nio.FileContentDecoder.transfer.

Transfers a portion of entity content from the underlying network channel into the given file channel.
Inherited from org.apache.hc.core5.http.impl.nio.AbstractContentDecoder:
bufferchannelfillBufferFromChannelgetTrailersisCompletedmetricsreadFromChannelreadFromChannelsetCompletedsetCompleted

Field Detail

contentLengthback to summary
private final long contentLength
lenback to summary
private long len

Constructor Detail

LengthDelimitedDecoderback to summary
public LengthDelimitedDecoder(final ReadableByteChannel channel, final SessionInputBuffer buffer, final BasicHttpTransportMetrics metrics, final long contentLength)

Method Detail

readback to summary
public int read(final ByteBuffer dst) throws IOException

Implements org.apache.hc.core5.http.nio.ContentDecoder.read.

Doc from org.apache.hc.core5.http.nio.ContentDecoder.read.

Reads a portion of content from the underlying channel

Parameters
dst:ByteBuffer

The buffer into which entity content is to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:
if I/O error occurs while reading content
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
transferback to summary
public long transfer(final FileChannel dst, final long position, final long count) throws IOException

Implements org.apache.hc.core5.http.nio.FileContentDecoder.transfer.

Doc from org.apache.hc.core5.http.nio.FileContentDecoder.transfer.

Transfers a portion of entity content from the underlying network channel into the given file channel.

Warning

Many implementations cannot write beyond the length of the file. If the position exceeds the channel's size, some implementations may throw an IOException.

Parameters
dst:FileChannel

the target FileChannel to transfer data into.

position:long

The position within the file at which the transfer is to begin; must be non-negative. Must be less than or equal to the size of the file

count:long

The maximum number of bytes to be transferred; must be non-negative

Returns:long

The number of bytes, possibly zero, that were actually transferred

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