Interface Content.Chunk

All Superinterfaces:
Retainable, RetainableByteBuffer
All Known Implementing Classes:
Content.Chunk.Empty, Trailers
Enclosing class:
Content

public static interface Content.Chunk extends RetainableByteBuffer

A chunk of content indicating whether it is the last chunk.

Optionally, a release function may be specified (for example to release the ByteBuffer back into a pool), or the Retainable.release() method overridden.

  • Field Details

    • EMPTY

      static final Content.Chunk EMPTY

      An empty, non-last, chunk instance.

    • EOF

      static final Content.Chunk EOF

      An empty, last, chunk.

  • Method Details

    • from

      static Content.Chunk from(ByteBuffer byteBuffer, boolean last)

      Creates a Chunk with the given ByteBuffer.

      The returned Chunk must be released.

      Parameters:
      byteBuffer - the ByteBuffer with the bytes of this Chunk
      last - whether the Chunk is the last one
      Returns:
      a new Chunk
    • from

      static Content.Chunk from(ByteBuffer byteBuffer, boolean last, Runnable releaser)

      Creates a Chunk with the given ByteBuffer.

      The returned Chunk must be released.

      Parameters:
      byteBuffer - the ByteBuffer with the bytes of this Chunk
      last - whether the Chunk is the last one
      releaser - the code to run when this Chunk is released
      Returns:
      a new Chunk
    • from

      static Content.Chunk from(ByteBuffer byteBuffer, boolean last, Consumer<ByteBuffer> releaser)

      Creates a last/non-last Chunk with the given ByteBuffer.

      The returned Chunk must be released.

      Parameters:
      byteBuffer - the ByteBuffer with the bytes of this Chunk
      last - whether the Chunk is the last one
      releaser - the code to run when this Chunk is released
      Returns:
      a new Chunk
    • asChunk

      static Content.Chunk asChunk(ByteBuffer byteBuffer, boolean last, Retainable retainable)

      Returns the given ByteBuffer and last arguments as a Chunk, linked to the given Retainable.

      The Retainable.retain() and Retainable.release() methods of this Chunk will delegate to the given Retainable.

      Parameters:
      byteBuffer - the ByteBuffer with the bytes of this Chunk
      last - whether the Chunk is the last one
      retainable - the Retainable this Chunk links to
      Returns:
      a new Chunk
    • from

      static Content.Chunk from(Throwable failure)

      Creates an failure chunk with the given failure and isLast() returning true.

      Parameters:
      failure - the cause of the failure
      Returns:
      a new failure chunk
    • from

      static Content.Chunk from(Throwable failure, boolean last)

      Creates an failure chunk with the given failure and given last state.

      Parameters:
      failure - the cause of the failure
      last - true if the failure is terminal, else false for transient failure
      Returns:
      a new failure chunk
    • next

      static Content.Chunk next(Content.Chunk chunk)

      Returns the chunk that follows the given chunk.

      Next Chunk
      Input Chunk Output Chunk
      null null
      Failure and last Error
      Failure and not last null
      isLast() EOF
      any other Chunk null
    • releaseAndNext

      static Content.Chunk releaseAndNext(Content.Chunk chunk)
      Convenience method to release a chunk and return next(Chunk). Equivalent to:
      
       if (chunk != null)
       {
           chunk.release();
           chunk = Chunk.next(chunk);
       }
       
      Parameters:
      chunk - The chunk to release or null
      Returns:
      The next(Chunk) chunk;
    • isFailure

      static boolean isFailure(Content.Chunk chunk)
      Parameters:
      chunk - The chunk to test for an failure.
      Returns:
      True if the chunk is non-null and chunk.getError() returns non-null.
    • isFailure

      static boolean isFailure(Content.Chunk chunk, boolean last)
      Parameters:
      chunk - The chunk to test for an failure
      last - The last status to test for.
      Returns:
      True if the chunk is non-null and getFailure() returns non-null and isLast() matches the passed status.
    • getFailure

      default Throwable getFailure()
      Get a failure (which may be from a failure or a warning), if any, associated with the chunk.
      Returns:
      A Throwable indicating the failure or null if there is no failure or warning.
      See Also:
    • isLast

      boolean isLast()
      Returns:
      whether this is the last Chunk
    • asReadOnly

      @Deprecated(forRemoval=true, since="12.1.0") default Content.Chunk asReadOnly()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      an immutable version of this Chunk