Class AvailableByteArrayBody
- All Implemented Interfaces:
AvailableByteBody
,ByteBody
,CloseableAvailableByteBody
,CloseableByteBody
,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 theExecutionFlow
API for extra efficiency.void
close()
Clean up any resources held by this instance.static @NonNull AvailableByteArrayBody
create
(@NonNull ByteBufferFactory<?, ?> bufferFactory, byte @NonNull [] array) Deprecated.static @NonNull AvailableByteArrayBody
create
(@NonNull ReadBuffer readBuffer) long
length()
The length in bytes of the body.move()
Create a newCloseableByteBody
with the same content but an independent lifecycle, claiming this body in the process.peek()
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 aReadBuffer
.Get this body as a reactive stream ofReadBuffer
s.Methods inherited from class io.micronaut.http.body.InternalByteBody
buffer, bufferFlow, failClaim, recordClosed, recordPrimaryOp, toByteArrayPublisher
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.http.body.AvailableByteBody
expectedLength, split, toByteArrayPublisher, toByteBuffer, toByteBufferPublisher, toInputStream, toString
Methods inherited from interface io.micronaut.http.body.CloseableAvailableByteBody
allowDiscard
-
Method Details
-
create
@Deprecated @NonNull public static @NonNull AvailableByteArrayBody create(@NonNull @NonNull ByteBufferFactory<?, ?> bufferFactory, byte @NonNull [] array) Deprecated.Construct throughByteBodyFactory
insteadCreates a newAvailableByteArrayBody
instance.- Parameters:
bufferFactory
- theByteBufferFactory
to use for creating buffersarray
- the byte array to wrap- Returns:
- a new
AvailableByteArrayBody
instance
-
create
@NonNull public static @NonNull AvailableByteArrayBody create(@NonNull @NonNull ReadBuffer readBuffer) -
split
Description copied from interface:AvailableByteBody
For immediate buffers, backpressure is not relevant, so the backpressure modes passed toAvailableByteBody.split(SplitBackpressureMode)
are ignored. You can use this method always.- Specified by:
split
in interfaceAvailableByteBody
- Specified by:
split
in interfaceByteBody
- Returns:
- A body with the same content as this one
- See Also:
-
length
public long length()Description copied from interface:AvailableByteBody
The length in bytes of the body.- Specified by:
length
in interfaceAvailableByteBody
- Returns:
- The length
- See Also:
-
toByteArray
Description copied from interface:AvailableByteBody
Get 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:
toByteArray
in interfaceAvailableByteBody
- Returns:
- The bytes
-
toReadBuffer
Description copied from interface:AvailableByteBody
Get this body as aReadBuffer
.This is a primary operation. After this operation, no other primary operation or
AvailableByteBody.split()
may be done.- Specified by:
toReadBuffer
in interfaceAvailableByteBody
- Returns:
- The bytes
-
toReadBufferPublisher
Description copied from interface:ByteBody
Get this body as a reactive stream ofReadBuffer
s. 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 interfaceAvailableByteBody
- Specified by:
toReadBufferPublisher
in interfaceByteBody
- Specified by:
toReadBufferPublisher
in classInternalByteBody
- Returns:
- The streamed bytes
-
move
Description copied from interface:ByteBody
Create a newCloseableByteBody
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 newCloseableByteBody
that the receiver is working with.- Specified by:
move
in interfaceByteBody
- Returns:
- A new
CloseableByteBody
with the same content.
-
close
public void close()Description copied from interface:CloseableByteBody
Clean up any resources held by this instance. See class documentation.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableByteBody
-
bufferFlow
Description copied from class:InternalByteBody
Variant ofInternalByteBody.buffer()
that uses theExecutionFlow
API for extra efficiency.- Specified by:
bufferFlow
in classInternalByteBody
- Returns:
- A flow that completes when all bytes are available
-
peek
-
ByteBodyFactory
instead