Class InputStreamByteBody

java.lang.Object
io.micronaut.http.body.stream.InputStreamByteBody
All Implemented Interfaces:
ByteBody, CloseableByteBody, InternalByteBody, Closeable, AutoCloseable

public final class InputStreamByteBody extends Object implements CloseableByteBody, InternalByteBody
ByteBody implementation that reads from an InputStream.
Since:
4.6.0
  • Method Details

    • create

      @NonNull public static @NonNull CloseableByteBody create(@NonNull @NonNull InputStream stream, @NonNull @NonNull OptionalLong length, @NonNull @NonNull Executor ioExecutor, @NonNull @NonNull io.micronaut.core.io.buffer.ByteBufferFactory<?,?> bufferFactory)
      Create a new stream-based CloseableByteBody. Ownership of the stream is transferred to the returned body.
      Parameters:
      stream - The stream backing the body
      length - The expected content length (see expectedLength())
      ioExecutor - An executor where blocking InputStream.read() may be performed
      bufferFactory - A ByteBufferFactory for buffer-based methods
      Returns:
      The body
    • allowDiscard

      @NonNull public @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
    • close

      public void close()
      Description copied from interface: CloseableByteBody
      Clean up any resources held by this instance. See class documentation.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CloseableByteBody
    • split

      @NonNull public @NonNull CloseableByteBody split(ByteBody.SplitBackpressureMode backpressureMode)
      Description copied from interface: ByteBody
      Create a new, independent ByteBody that contains the same data as this one.
      Specified by:
      split in interface ByteBody
      Parameters:
      backpressureMode - How to handle backpressure between the old and new body. See ByteBody.SplitBackpressureMode documentation
      Returns:
      The newly split body. Must be closed by the caller, unless a terminal operation is performed on it
    • expectedLength

      @NonNull public @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
    • toInputStream

      @NonNull public @NonNull io.micronaut.http.body.stream.ExtendedInputStream 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
    • toByteArrayPublisher

      @NonNull public @NonNull reactor.core.publisher.Flux<byte[]> toByteArrayPublisher()
      Description copied from interface: ByteBody
      Get this body as a reactive stream of byte arrays.

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

      Specified by:
      toByteArrayPublisher in interface ByteBody
      Returns:
      The streamed bytes
    • toByteBufferPublisher

      @NonNull public @NonNull org.reactivestreams.Publisher<io.micronaut.core.io.buffer.ByteBuffer<?>> toByteBufferPublisher()
      Description copied from interface: ByteBody
      Get this body as a reactive stream of ByteBuffers. Note that the buffers may be reference counted, and the caller must take care of releasing them.

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

      Specified by:
      toByteBufferPublisher in interface ByteBody
      Returns:
      The streamed bytes
    • bufferFlow

      @NonNull public @NonNull io.micronaut.core.execution.ExecutionFlow<? extends CloseableAvailableByteBody> bufferFlow()
      Description copied from interface: InternalByteBody
      Variant of InternalByteBody.buffer() that uses the ExecutionFlow API for extra efficiency.
      Specified by:
      bufferFlow in interface InternalByteBody
      Returns:
      A flow that completes when all bytes are available