Class BaseStreamingByteBody<SB extends BaseSharedBuffer>

java.lang.Object
io.micronaut.http.body.InternalByteBody
io.micronaut.http.body.stream.BaseStreamingByteBody<SB>
Type Parameters:
SB - The shared buffer type
All Implemented Interfaces:
ByteBody, CloseableByteBody, Closeable, AutoCloseable
Direct Known Subclasses:
ReactiveByteBufferByteBody, StreamingNettyByteBody

@Internal public abstract class BaseStreamingByteBody<SB extends BaseSharedBuffer> extends InternalByteBody implements CloseableByteBody
Implementation of streaming ByteBodys based on a BaseSharedBuffer.
Since:
4.10.0
Author:
Jonas Konrad
  • Field Details

  • Constructor Details

  • Method Details

    • expectedLength

      @NonNull public final @NonNull OptionalLong expectedLength()
      Description copied from interface: ByteBody
      Get the expected length of this body, if known (either from Content-Length or from previous buffering). The actual length will never exceed this value, though it may sometimes be lower if there is a connection error.

      This value may go from OptionalLong.empty() to a known value over the lifetime of this body.

      This is not a primary operation and does not modify this ByteBody.

      Specified by:
      expectedLength in interface ByteBody
      Returns:
      The expected length of this body
    • primary

      Consume this buffer.
      Parameters:
      primary - The consumer or null to discard the data
      Returns:
      The upstream to signal backpressure
    • derive

      Create a new body instance on the same shared buffer with the given upstream. This is used for move().
      Parameters:
      upstream - The upstream
      Returns:
      The body
    • toReadBufferPublisher

      @NonNull public final @NonNull Publisher<ReadBuffer> toReadBufferPublisher()
      Description copied from interface: ByteBody
      Get this body as a reactive stream of ReadBuffers. Note that the caller must take care to release the returned buffers.

      This is a primary operation. After this operation, no other primary operation or ByteBody.split() may be done.

      Specified by:
      toReadBufferPublisher in interface ByteBody
      Specified by:
      toReadBufferPublisher in class InternalByteBody
      Returns:
      The streamed bytes
    • toInputStream

      @NonNull public final @NonNull InputStream toInputStream()
      Description copied from interface: ByteBody
      Get this body as an InputStream.

      This is a primary operation. After this operation, no other primary operation or ByteBody.split() may be done.

      Specified by:
      toInputStream in interface ByteBody
      Returns:
      The streamed bytes
    • move

      @NonNull public final @NonNull CloseableByteBody move()
      Description copied from interface: ByteBody
      Create a new CloseableByteBody with the same content but an independent lifecycle, claiming this body in the process.

      This is a primary operation. After this operation, no other primary operation or ByteBody.split() may be done.

      The purpose of this method is to move the data to a different component in an application, making clear that the receiving component claims ownership of the body. If the sending component then closes the original ByteBody for example, it will have no impact on the new CloseableByteBody that the receiver is working with.

      Specified by:
      move in interface ByteBody
      Returns:
      A new CloseableByteBody with the same content.
    • allowDiscard

      @NonNull public final @NonNull CloseableByteBody allowDiscard()
      Description copied from interface: ByteBody
      Signal that the upstream may discard any remaining body data. Only if all consumers of the body allow discarding will the body be discarded, otherwise it will still be sent to all consumers. It is an optional operation.

      Discarding may be implemented e.g. by closing the input side of an HTTP/2 stream.

      This method must be called before any primary operation.

      Specified by:
      allowDiscard in interface ByteBody
      Specified by:
      allowDiscard in interface CloseableByteBody
      Returns:
      This body