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
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSpecific(@NonNull Argument<T> type) Prepare aMessageBodyWriterthat will write the given type.booleantrueiff this closure can do a blocking read on the object it receives.booleanIs 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.voidwriteTo(@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:MessageBodyWriterIs the type writeable.- Specified by:
isWriteablein interfaceMessageBodyWriter<T>- Parameters:
type- The typemediaType- The media type, can benull- Returns:
- True if is writable
-
createSpecific
Description copied from interface:MessageBodyWriterPrepare aMessageBodyWriterthat will write the given type. This can be used for precomputing some route data.- Specified by:
createSpecificin interfaceMessageBodyWriter<T>- Parameters:
type- The type- Returns:
- The closure
-
isBlocking
public boolean isBlocking()Description copied from interface:MessageBodyWritertrueiff 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 theOutputStreamthat is passed as the write destination may still block.- Specified by:
isBlockingin 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:MessageBodyWriterWrites an object to the given output stream.- Specified by:
writeToin 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:MessageBodyWriterWrites an object to the given stream.- Specified by:
writeToin 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:ResponseBodyWriterWrites an object as aByteBodyHttpResponse.- Specified by:
writein interfaceResponseBodyWriter<T>- Parameters:
bufferFactory- The buffer factoryrequest- The requesthttpResponse- The responsetype- The response body typemediaType- The media typeobject- The object to write- Returns:
- A
ByteBodyHttpResponsewith the response bytes - Throws:
CodecException- If an error occurs encoding
-