org.apache.hc.core5.http.impl.nio

## Class AbstractContentEncoder

- java.lang.Object
- - org.apache.hc.core5.http.impl.nio.AbstractContentEncoder

- All Implemented Interfaces:
    ContentEncoder
  Direct Known Subclasses:
    ChunkEncoder, IdentityEncoder, LengthDelimitedEncoder

      public abstract class AbstractContentEncoder
      extends Object
      implements ContentEncoder

  Abstract `ContentEncoder` that serves as a base for all content encoder implementations.
  Since:
    4.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractContentEncoder(WritableByteChannel channel, SessionOutputBuffer buffer, BasicHttpTransportMetrics metrics)` Creates an instance of this class.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `assertNotCompleted()`
    `protected SessionOutputBuffer` | `buffer()`
    `protected WritableByteChannel` | `channel()`
    `void` | `complete()`
    `void` | `complete(List<? extends Header> trailers)` Terminates the content stream.
    `protected int` | `flushToChannel()` Flushes content of the session buffer to the channel and updates transport metrics.
    `boolean` | `isCompleted()` Returns `true` if the entity has been transferred in its entirety.
    `protected BasicHttpTransportMetrics` | `metrics()`
    `protected int` | `writeToBuffer(ByteBuffer src, int limit)` Transfers content of the source to the buffer and updates transport metrics.
    `protected int` | `writeToChannel(ByteBuffer src)` Flushes content of the given buffer to the channel and updates transport metrics.
    `protected int` | `writeToChannel(ByteBuffer src, int limit)` Transfers content of the source to the channel and updates transport metrics.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.hc.core5.http.nio.ContentEncoder

      `write`

- - ### Constructor Detail

    - #### AbstractContentEncoder

          public AbstractContentEncoder(WritableByteChannel channel,
                                SessionOutputBuffer buffer,
                                BasicHttpTransportMetrics metrics)

      Creates an instance of this class.
      Parameters:
        `channel` - the destination channel.
        `buffer` - the session output buffer that can be used to store session data for intermediate processing.
        `metrics` - Transport metrics of the underlying HTTP transport.

  - ### Method Detail

    - #### channel

          protected WritableByteChannel channel()

    - #### buffer

          protected SessionOutputBuffer buffer()

    - #### metrics

          protected BasicHttpTransportMetrics metrics()

    - #### isCompleted

          public boolean isCompleted()

      Description copied from interface: `ContentEncoder`
      Returns `true` if the entity has been transferred in its entirety.
      Specified by:
        `isCompleted` in interface `ContentEncoder`
      Returns:
        `true` if all the content has been produced, `false` otherwise.

    - #### complete

          public void complete(List<? extends Header> trailers)
                        throws IOException

      Description copied from interface: `ContentEncoder`
      Terminates the content stream.
      Specified by:
        `complete` in interface `ContentEncoder`
      Throws:
        `IOException` - if I/O error occurs while writing content

    - #### complete

          public final void complete()
                              throws IOException

      Throws:
        `IOException`

    - #### assertNotCompleted

          protected void assertNotCompleted()

    - #### flushToChannel

          protected int flushToChannel()
                                throws IOException

      Flushes content of the session buffer to the channel and updates transport metrics.
      Returns:
        number of bytes written to the channel.
      Throws:
        `IOException`
      Since:
        4.3

    - #### writeToChannel

          protected int writeToChannel(ByteBuffer src)
                                throws IOException

      Flushes content of the given buffer to the channel and updates transport metrics.
      Returns:
        number of bytes written to the channel.
      Throws:
        `IOException`
      Since:
        4.3

    - #### writeToChannel

          protected int writeToChannel(ByteBuffer src,
                           int limit)
                                throws IOException

      Transfers content of the source to the channel and updates transport metrics.
      Parameters:
        `src` - source.
        `limit` - max number of bytes to transfer.
      Returns:
        number of bytes transferred.
      Throws:
        `IOException`
      Since:
        4.3

    - #### writeToBuffer

          protected int writeToBuffer(ByteBuffer src,
                          int limit)
                               throws IOException

      Transfers content of the source to the buffer and updates transport metrics.
      Parameters:
        `src` - source.
        `limit` - max number of bytes to transfer.
      Returns:
        number of bytes transferred.
      Throws:
        `IOException`
      Since:
        4.3

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.