Package io.micronaut.http.netty.body
Class NettyByteBodyFactory
java.lang.Object
io.micronaut.http.body.ByteBodyFactory
io.micronaut.http.netty.body.NettyByteBodyFactory
ByteBodyFactory
implementation with netty-optimized bodies.- Since:
- 4.8.0
- Author:
- Jonas Konrad
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreate a newCloseableAvailableByteBody
from the given array.adapt
(@NonNull ByteBuffer<?> buffer) Create a newCloseableAvailableByteBody
from the given buffer.<T extends Throwable>
@NonNull CloseableAvailableByteBodybuffer
(@NonNull ThrowingConsumer<? super OutputStream, T> writer) Buffer any data written to anOutputStream
and return it as aByteBody
.copyOf
(@NonNull InputStream stream) Copy the data of the givenInputStream
into an availableByteBody
.copyOf
(@NonNull CharSequence cs, @NonNull Charset charset) Encode the givenCharSequence
and create aByteBody
from it.Create an empty body.Methods inherited from class io.micronaut.http.body.ByteBodyFactory
byteBufferFactory, createDefault
-
Constructor Details
-
NettyByteBodyFactory
-
-
Method Details
-
adapt
Description copied from class:ByteBodyFactory
Create a newCloseableAvailableByteBody
from the given buffer. Ownership of the buffer is transferred to this method; the original buffer may be copied or used as-is depending on implementation. If the buffer isReferenceCounted
, release ownership is also transferred to this method.- Overrides:
adapt
in classByteBodyFactory
- Parameters:
buffer
- The buffer- Returns:
- A
ByteBody
with the same content as the buffer
-
adapt
Description copied from class:ByteBodyFactory
Create a newCloseableAvailableByteBody
from the given array. Ownership of the array is transferred to this method; the array may be copied or used as-is, so do not modify the array after passing it to this method.- Overrides:
adapt
in classByteBodyFactory
- Parameters:
array
- The array- Returns:
- A
ByteBody
with the same content as the array
-
buffer
@NonNull public <T extends Throwable> @NonNull CloseableAvailableByteBody buffer(@NonNull @NonNull ThrowingConsumer<? super OutputStream, T> writer) throws TDescription copied from class:ByteBodyFactory
Buffer any data written to anOutputStream
and return it as aByteBody
.- Overrides:
buffer
in classByteBodyFactory
- Type Parameters:
T
- Exception type thrown by the consumer- Parameters:
writer
- The function that will write to theOutputStream
- Returns:
- The data written to the stream
- Throws:
T
- Exception thrown by the consumer
-
createEmpty
Description copied from class:ByteBodyFactory
Create an empty body.- Overrides:
createEmpty
in classByteBodyFactory
- Returns:
- The empty body
-
copyOf
@NonNull public @NonNull CloseableAvailableByteBody copyOf(@NonNull @NonNull CharSequence cs, @NonNull @NonNull Charset charset) Description copied from class:ByteBodyFactory
Encode the givenCharSequence
and create aByteBody
from it.- Overrides:
copyOf
in classByteBodyFactory
- Parameters:
cs
- The input stringcharset
- The charset to use for encoding- Returns:
- The encoded body
-
copyOf
@NonNull public @NonNull CloseableAvailableByteBody copyOf(@NonNull @NonNull InputStream stream) throws IOException Description copied from class:ByteBodyFactory
Copy the data of the givenInputStream
into an availableByteBody
. If the input is blocking, this method will also block.- Overrides:
copyOf
in classByteBodyFactory
- Parameters:
stream
- The input to copy- Returns:
- A body containing the data read from the input
- Throws:
IOException
- Any exception thrown by theInputStream
read methods
-