Package io.micronaut.http.body
Class ResponseBodyWriterWrapper<T>
java.lang.Object
io.micronaut.http.body.ResponseBodyWriterWrapper<T>
- Type Parameters:
T
- The body type
- All Implemented Interfaces:
MessageBodyWriter<T>
,ResponseBodyWriter<T>
ResponseBodyWriter
implementation that delegates to a MessageBodyWriter
.- Since:
- 4.7.0
- Author:
- Jonas Konrad
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific
(@NonNull Argument<T> type) Prepare aMessageBodyWriter
that will write the given type.boolean
true
iff this closure can do a blocking read on the object it receives.boolean
Is the type writeable.write
(@NonNull ByteBufferFactory<?, ?> bufferFactory, @NonNull HttpRequest<?> request, @NonNull MutableHttpResponse<T> httpResponse, @NonNull Argument<T> type, @NonNull MediaType mediaType, T object) Writes an object as aByteBodyHttpResponse
.writeTo
(@NonNull Argument<T> type, @NonNull MediaType mediaType, T object, @NonNull MutableHeaders outgoingHeaders, @NonNull ByteBufferFactory<?, ?> bufferFactory) Writes an object to the given stream.void
writeTo
(@NonNull Argument<T> type, @NonNull MediaType mediaType, T object, @NonNull MutableHeaders outgoingHeaders, @NonNull OutputStream outputStream) Writes an object to the given output stream.
-
Constructor Details
-
ResponseBodyWriterWrapper
-
-
Method Details
-
isWriteable
public boolean isWriteable(@NonNull @NonNull Argument<T> type, @Nullable @Nullable MediaType mediaType) Description copied from interface:MessageBodyWriter
Is the type writeable.- Specified by:
isWriteable
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The typemediaType
- The media type, can benull
- Returns:
- True if is writable
-
createSpecific
Description copied from interface:MessageBodyWriter
Prepare aMessageBodyWriter
that will write the given type. This can be used for precomputing some route data.- Specified by:
createSpecific
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The type- Returns:
- The closure
-
isBlocking
public boolean isBlocking()Description copied from interface:MessageBodyWriter
true
iff this closure can do a blocking read on the object it receives. For example, if this closure writes from anInputStream
, that operation may be blocking and this method returnstrue
.
Note that even when this isfalse
,MessageBodyWriter.writeTo(Argument, MediaType, Object, MutableHeaders, OutputStream)
may still block because theOutputStream
that is passed as the write destination may still block.- Specified by:
isBlocking
in interfaceMessageBodyWriter<T>
- Returns:
- Whether this writer may block
-
writeTo
public void writeTo(@NonNull @NonNull Argument<T> type, @NonNull @NonNull MediaType mediaType, T object, @NonNull @NonNull MutableHeaders outgoingHeaders, @NonNull @NonNull OutputStream outputStream) throws CodecException Description copied from interface:MessageBodyWriter
Writes an object to the given output stream.- Specified by:
writeTo
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The typemediaType
- The media typeobject
- The object to writeoutgoingHeaders
- The HTTP headersoutputStream
- The output stream- Throws:
CodecException
- If an error occurs decoding
-
writeTo
@NonNull public @NonNull ByteBuffer<?> writeTo(@NonNull @NonNull Argument<T> type, @NonNull @NonNull MediaType mediaType, T object, @NonNull @NonNull MutableHeaders outgoingHeaders, @NonNull @NonNull ByteBufferFactory<?, ?> bufferFactory) throws CodecExceptionDescription copied from interface:MessageBodyWriter
Writes an object to the given stream.- Specified by:
writeTo
in interfaceMessageBodyWriter<T>
- Parameters:
type
- The typemediaType
- The media typeobject
- The object to writeoutgoingHeaders
- The HTTP headersbufferFactory
- A byte buffer factory- Returns:
- The encoded byte buffer
- Throws:
CodecException
- If an error occurs decoding
-
write
@NonNull public @NonNull ByteBodyHttpResponse<?> write(@NonNull @NonNull ByteBufferFactory<?, ?> bufferFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull MutableHttpResponse<T> httpResponse, @NonNull @NonNull Argument<T> type, @NonNull @NonNull MediaType mediaType, T object) throws CodecExceptionDescription copied from interface:ResponseBodyWriter
Writes an object as aByteBodyHttpResponse
.- Specified by:
write
in interfaceResponseBodyWriter<T>
- Parameters:
bufferFactory
- The buffer factoryrequest
- The requesthttpResponse
- The responsetype
- The response body typemediaType
- The media typeobject
- The object to write- Returns:
- A
ByteBodyHttpResponse
with the response bytes - Throws:
CodecException
- If an error occurs encoding
-