Class LengthDelimitedEncoder
java.lang.Object
org.apache.http.impl.nio.codecs.AbstractContentEncoder
org.apache.http.impl.nio.codecs.LengthDelimitedEncoder
- All Implemented Interfaces:
ContentEncoder, FileContentEncoder
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
Fields inherited from class AbstractContentEncoder
buffer, channel, completed, metrics -
Constructor Summary
ConstructorsConstructorDescriptionLengthDelimitedEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, org.apache.http.impl.io.HttpTransportMetricsImpl metrics, long contentLength) LengthDelimitedEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, org.apache.http.impl.io.HttpTransportMetricsImpl metrics, long contentLength, int fragementSizeHint) -
Method Summary
Modifier and TypeMethodDescriptiontoString()longtransfer(FileChannel src, long position, long count) Transfers a portion of entity content from the given file channel to the underlying network channel.intwrite(ByteBuffer src) Writes a portion of entity content to the underlying channel.Methods inherited from class AbstractContentEncoder
assertNotCompleted, complete, flushToChannel, isCompleted, writeToBuffer, writeToChannel, writeToChannelMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ContentEncoder
complete, isCompleted
-
Constructor Details
-
LengthDelimitedEncoder
public LengthDelimitedEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, org.apache.http.impl.io.HttpTransportMetricsImpl metrics, long contentLength, int fragementSizeHint) - Parameters:
channel- underlying channel.buffer- session buffer.metrics- transport metrics.contentLength- content length.fragementSizeHint- fragment size hint defining an minimal size of a fragment that should be written out directly to the channel bypassing the session buffer. Value0disables fragment buffering.- Since:
- 4.3
-
LengthDelimitedEncoder
public LengthDelimitedEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, org.apache.http.impl.io.HttpTransportMetricsImpl metrics, long contentLength)
-
-
Method Details
-
write
Description copied from interface:ContentEncoderWrites a portion of entity content to the underlying channel.- Specified by:
writein interfaceContentEncoder- Parameters:
src- The buffer from which content is to be retrieved- Returns:
- The number of bytes read, possibly zero
- Throws:
IOException- if I/O error occurs while writing content
-
transfer
Description copied from interface:FileContentEncoderTransfers a portion of entity content from the given file channel to the underlying network channel.- Specified by:
transferin interfaceFileContentEncoder- Parameters:
src- the source FileChannel to transfer data from.position- The position within the file at which the transfer is to begin; must be non-negativecount- The maximum number of bytes to be transferred; must be non-negative- Returns:
- The number of bytes, possibly zero, that were actually transferred
- Throws:
IOException- if some I/O error occurs.
-
toString
-