Class InputStreamByteBody
- All Implemented Interfaces:
ByteBody,CloseableByteBody,Closeable,AutoCloseable
ByteBody implementation that reads from an InputStream.- Since:
- 4.6.0
- Author:
- Jonas Konrad
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.http.body.ByteBody
ByteBody.BodyDiscardedException, ByteBody.SplitBackpressureMode -
Method Summary
Modifier and TypeMethodDescriptionSignal that the upstream may discard any remaining body data.@NonNull ExecutionFlow<? extends CloseableAvailableByteBody>Variant ofInternalByteBody.buffer()that uses theExecutionFlowAPI for extra efficiency.voidclose()Clean up any resources held by this instance.static @NonNull CloseableByteBodycreate(@NonNull InputStream stream, @NonNull OptionalLong length, @NonNull Executor ioExecutor, @NonNull ByteBufferFactory<?, ?> bufferFactory) Deprecated.static @NonNull CloseableByteBodycreate(@NonNull InputStream stream, @NonNull OptionalLong length, @NonNull Executor ioExecutor, @NonNull ByteBodyFactory bodyFactory) Create a new stream-basedCloseableByteBody.Get the expected length of this body, if known (either fromContent-Lengthor from previous buffering).move()Create a newCloseableByteBodywith the same content but an independent lifecycle, claiming this body in the process.split(ByteBody.SplitBackpressureMode backpressureMode) Create a new, independentByteBodythat contains the same data as this one.@NonNull reactor.core.publisher.Flux<byte[]>Get this body as a reactive stream of byte arrays.@NonNull io.micronaut.http.body.stream.ExtendedInputStreamGet this body as anInputStream.Get this body as a reactive stream ofReadBuffers.Methods inherited from class io.micronaut.http.body.InternalByteBody
buffer, bufferFlow, failClaim, recordClosed, recordPrimaryOpMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.body.ByteBody
buffer, split, toByteBufferPublisher, touch
-
Method Details
-
create
@NonNull public static @NonNull CloseableByteBody create(@NonNull @NonNull InputStream stream, @NonNull @NonNull OptionalLong length, @NonNull @NonNull Executor ioExecutor, @NonNull @NonNull ByteBufferFactory<?, ?> bufferFactory) Deprecated.Please pass aByteBodyFactoryinstead (create(InputStream, OptionalLong, Executor, ByteBodyFactory))Create a new stream-basedCloseableByteBody. Ownership of the stream is transferred to the returned body.- Parameters:
stream- The stream backing the bodylength- The expected content length (seeexpectedLength())ioExecutor- An executor where blockingInputStream.read()may be performedbufferFactory- AByteBufferFactoryfor buffer-based methods- Returns:
- The body
-
create
@NonNull public static @NonNull CloseableByteBody create(@NonNull @NonNull InputStream stream, @NonNull @NonNull OptionalLong length, @NonNull @NonNull Executor ioExecutor, @NonNull @NonNull ByteBodyFactory bodyFactory) Create a new stream-basedCloseableByteBody. Ownership of the stream is transferred to the returned body.- Parameters:
stream- The stream backing the bodylength- The expected content length (seeexpectedLength())ioExecutor- An executor where blockingInputStream.read()may be performedbodyFactory- AByteBodyFactoryfor buffer-based methods- Returns:
- The body
-
allowDiscard
Description copied from interface:ByteBodySignal 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:
allowDiscardin interfaceByteBody- Specified by:
allowDiscardin interfaceCloseableByteBody- Returns:
- This body
-
close
public void close()Description copied from interface:CloseableByteBodyClean up any resources held by this instance. See class documentation.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCloseableByteBody
-
split
Description copied from interface:ByteBodyCreate a new, independentByteBodythat contains the same data as this one.- Specified by:
splitin interfaceByteBody- Parameters:
backpressureMode- How to handle backpressure between the old and new body. SeeByteBody.SplitBackpressureModedocumentation- Returns:
- The newly split body. Must be closed by the caller, unless a terminal operation is performed on it
-
expectedLength
Description copied from interface:ByteBodyGet the expected length of this body, if known (either fromContent-Lengthor 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:
expectedLengthin interfaceByteBody- Returns:
- The expected length of this body
-
toInputStream
Description copied from interface:ByteBodyGet this body as anInputStream.This is a primary operation. After this operation, no other primary operation or
ByteBody.split()may be done.- Specified by:
toInputStreamin interfaceByteBody- Returns:
- The streamed bytes
-
toByteArrayPublisher
Description copied from interface:ByteBodyGet 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:
toByteArrayPublisherin interfaceByteBody- Overrides:
toByteArrayPublisherin classInternalByteBody- Returns:
- The streamed bytes
-
toReadBufferPublisher
Description copied from interface:ByteBodyGet this body as a reactive stream ofReadBuffers. 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:
toReadBufferPublisherin interfaceByteBody- Specified by:
toReadBufferPublisherin classInternalByteBody- Returns:
- The streamed bytes
-
bufferFlow
Description copied from class:InternalByteBodyVariant ofInternalByteBody.buffer()that uses theExecutionFlowAPI for extra efficiency.- Specified by:
bufferFlowin classInternalByteBody- Returns:
- A flow that completes when all bytes are available
-
move
Description copied from interface:ByteBodyCreate a newCloseableByteBodywith 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
ByteBodyfor example, it will have no impact on the newCloseableByteBodythat the receiver is working with.- Specified by:
movein interfaceByteBody- Returns:
- A new
CloseableByteBodywith the same content.
-
ByteBodyFactoryinstead (create(InputStream, OptionalLong, Executor, ByteBodyFactory))