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

public Class LengthDelimitedEncoder

extends AbstractContentEncoder
implements FileContentEncoder
Class Inheritance
All Implemented Interfaces
org.apache.hc.core5.http.nio.FileContentEncoder, org.apache.hc.core5.http.nio.ContentEncoder
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, .WritableByteChannel, org.apache.hc.core5.http.impl.BasicHttpTransportMetrics, org.apache.hc.core5.http.nio.FileContentEncoder, .SessionOutputBuffer, org.apache.hc.core5.util.Args

Content encoder that cuts off after a defined number of bytes. This class is used to send 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 a FileChannel to the underlying I/O session's channel whenever possible avoiding intermediate buffering in the session buffer.

Since
4.0

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
LengthDelimitedEncoder(final WritableByteChannel
underlying channel.
channel
,
final SessionOutputBuffer
session buffer.
buffer
,
final BasicHttpTransportMetrics
transport metrics.
metrics
,
final long
content length.
contentLength
,
final int
fragment size hint defining an minimal size of a fragment that should be written out directly to the channel bypassing the session buffer. Value 0 disables fragment buffering.
chunkSizeHint
)

public
LengthDelimitedEncoder(final WritableByteChannel channel, final SessionOutputBuffer buffer, final BasicHttpTransportMetrics metrics, final long contentLength)

Method Summary

Modifier and TypeMethod and Description
private int
nextChunk(final ByteBuffer src)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public long
transfer(final FileChannel
the source FileChannel to transfer data from.
src
,
final long
The position within the file at which the transfer is to begin; must be non-negative
position
,
final long
The maximum number of bytes to be transferred; must be non-negative
count
)

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

Transfers a portion of entity content from the given file channel to the underlying network channel.
public int
write(final ByteBuffer
The buffer from which content is to be retrieved
src
)

Implements org.apache.hc.core5.http.nio.ContentEncoder.write.

Writes a portion of entity content to the underlying channel.
Inherited from org.apache.hc.core5.http.impl.nio.AbstractContentEncoder:
assertNotCompletedbufferchannelcompletecompleteflushToChannelisCompletedmetricswriteToBufferwriteToChannelwriteToChannel

Field Detail

contentLengthback to summary
private final long contentLength
fragHintback to summary
private final int fragHint
remainingback to summary
private long remaining

Constructor Detail

LengthDelimitedEncoderback to summary
public LengthDelimitedEncoder(final WritableByteChannel channel, final SessionOutputBuffer buffer, final BasicHttpTransportMetrics metrics, final long contentLength, final int chunkSizeHint)
Parameters
channel:WritableByteChannel

underlying channel.

buffer:SessionOutputBuffer

session buffer.

metrics:BasicHttpTransportMetrics

transport metrics.

contentLength:long

content length.

chunkSizeHint:int

fragment size hint defining an minimal size of a fragment that should be written out directly to the channel bypassing the session buffer. Value 0 disables fragment buffering.

Since
4.3
LengthDelimitedEncoderback to summary
public LengthDelimitedEncoder(final WritableByteChannel channel, final SessionOutputBuffer buffer, final BasicHttpTransportMetrics metrics, final long contentLength)

Method Detail

nextChunkback to summary
private int nextChunk(final ByteBuffer src)
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 src, final long position, final long count) throws IOException

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

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

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

Parameters
src:FileChannel

the source FileChannel to transfer data from.

position:long

The position within the file at which the transfer is to begin; must be non-negative

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.
writeback to summary
public int write(final ByteBuffer src) throws IOException

Implements org.apache.hc.core5.http.nio.ContentEncoder.write.

Doc from org.apache.hc.core5.http.nio.ContentEncoder.write.

Writes a portion of entity content to the underlying channel.

Parameters
src:ByteBuffer

The buffer from which content is to be retrieved

Returns:int

The number of bytes read, possibly zero

Annotations
@Override
Exceptions
IOException:
if I/O error occurs while writing content