Class LengthDelimitedEncoder

  • All Implemented Interfaces:
    ContentEncoder, FileContentEncoder

    public class LengthDelimitedEncoder
    extends AbstractContentEncoder
    implements 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.

    • Constructor Detail

      • LengthDelimitedEncoder

        public LengthDelimitedEncoder​(java.nio.channels.WritableByteChannel channel,
                                      SessionOutputBuffer buffer,
                                      HttpTransportMetricsImpl metrics,
                                      long contentLength,
                                      int fragementSizeHint)
        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. Value 0 disables fragment buffering.
    • Method Detail

      • write

        public int write​(java.nio.ByteBuffer src)
        Description copied from interface: ContentEncoder
        Writes a portion of entity content to the underlying channel.
        Specified by:
        write in interface ContentEncoder
        src - The buffer from which content is to be retrieved
        The number of bytes read, possibly zero
        Throws: - if I/O error occurs while writing content
      • transfer

        public long transfer​(java.nio.channels.FileChannel src,
                             long position,
                             long count)
        Description copied from interface: FileContentEncoder
        Transfers a portion of entity content from the given file channel to the underlying network channel.
        Specified by:
        transfer in interface FileContentEncoder
        src - the source FileChannel to transfer data from.
        position - The position within the file at which the transfer is to begin; must be non-negative
        count - The maximum number of bytes to be transferred; must be non-negative
        The number of bytes, possibly zero, that were actually transferred
        Throws: - if some I/O error occurs.
      • toString

        public java.lang.String toString()
        toString in class java.lang.Object