Class AvailableByteArrayBody
- All Implemented Interfaces:
AvailableByteBody,ByteBody,CloseableAvailableByteBody,CloseableByteBody,InternalByteBody,Closeable,AutoCloseable
AvailableByteBody implementation based on a simple byte array.- 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 TypeMethodDescription@NonNull ExecutionFlow<? extends CloseableAvailableByteBody>Variant ofInternalByteBody.buffer()that uses theExecutionFlowAPI for extra efficiency.voidclose()Clean up any resources held by this instance.static @NonNull AvailableByteArrayBodycreate(@NonNull ByteBufferFactory<?, ?> bufferFactory, byte @NonNull [] array) longlength()The length in bytes of the body.move()Create a newCloseableByteBodywith the same content but an independent lifecycle, claiming this body in the process.split()For immediate buffers, backpressure is not relevant, so the backpressure modes passed toAvailableByteBody.split(SplitBackpressureMode)are ignored.byte @NonNull []Get this body as a byte array.Get this body as aByteBuffer.Get this body as anInputStream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.body.AvailableByteBody
expectedLength, split, toByteArrayPublisher, toByteBufferPublisher, toStringMethods inherited from interface io.micronaut.http.body.CloseableAvailableByteBody
allowDiscardMethods inherited from interface io.micronaut.http.body.InternalByteBody
buffer
-
Method Details
-
create
@NonNull public static @NonNull AvailableByteArrayBody create(@NonNull @NonNull ByteBufferFactory<?, ?> bufferFactory, byte @NonNull [] array) -
split
Description copied from interface:AvailableByteBodyFor immediate buffers, backpressure is not relevant, so the backpressure modes passed toAvailableByteBody.split(SplitBackpressureMode)are ignored. You can use this method always.- Specified by:
splitin interfaceAvailableByteBody- Specified by:
splitin interfaceByteBody- Returns:
- A body with the same content as this one
- See Also:
-
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
-
length
public long length()Description copied from interface:AvailableByteBodyThe length in bytes of the body.- Specified by:
lengthin interfaceAvailableByteBody- Returns:
- The length
- See Also:
-
toByteArray
Description copied from interface:AvailableByteBodyGet this body as a byte array.This is a primary operation. After this operation, no other primary operation or
AvailableByteBody.split()may be done.- Specified by:
toByteArrayin interfaceAvailableByteBody- Returns:
- The bytes
-
toByteBuffer
Description copied from interface:AvailableByteBodyGet this body as aByteBuffer. Note that the buffer may bereference counted, and the caller must take care of releasing it.This is a primary operation. After this operation, no other primary operation or
AvailableByteBody.split()may be done.- Specified by:
toByteBufferin interfaceAvailableByteBody- Returns:
- The bytes
-
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.
-
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
-
bufferFlow
Description copied from interface:InternalByteBodyVariant ofInternalByteBody.buffer()that uses theExecutionFlowAPI for extra efficiency.- Specified by:
bufferFlowin interfaceInternalByteBody- Returns:
- A flow that completes when all bytes are available
-