Package io.micronaut.http.body
Class WritableBodyWriter
java.lang.Object
io.micronaut.http.body.WritableBodyWriter
- All Implemented Interfaces:
- ChunkedMessageBodyReader<Writable>,- MessageBodyHandler<Writable>,- MessageBodyReader<Writable>,- MessageBodyWriter<Writable>,- ResponseBodyWriter<Writable>,- TypedMessageBodyHandler<Writable>,- TypedMessageBodyReader<Writable>,- TypedMessageBodyWriter<Writable>
@Singleton
public final class WritableBodyWriter
extends Object
implements TypedMessageBodyHandler<Writable>, ChunkedMessageBodyReader<Writable>, ResponseBodyWriter<Writable>
Body writer for 
Writables.- Since:
- 4.0.0
- Author:
- Graeme Rocher
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptiongetType()booleantrueiff this closure can do a blocking read on the object it receives.Reads an object from the given byte buffer.Reads an object from the given byte buffer.readChunked(Argument<Writable> type, MediaType mediaType, Headers httpHeaders, Publisher<ByteBuffer<?>> input) writePiece(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull HttpResponse<?> response, @NonNull Argument<Writable> type, @NonNull MediaType mediaType, Writable object) Write a piece of a larger response, e.g.voidwriteTo(Argument<Writable> type, MediaType mediaType, Writable object, MutableHeaders outgoingHeaders, OutputStream outputStream) Writes an object to the given output stream.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.body.MessageBodyWritercreateSpecific, writeToMethods inherited from interface io.micronaut.http.body.ResponseBodyWriterwriteMethods inherited from interface io.micronaut.http.body.TypedMessageBodyReaderisReadableMethods inherited from interface io.micronaut.http.body.TypedMessageBodyWriterisWriteable
- 
Constructor Details- 
WritableBodyWriter
 
- 
- 
Method Details- 
getType- Specified by:
- getTypein interface- TypedMessageBodyHandler<Writable>
- Specified by:
- getTypein interface- TypedMessageBodyReader<Writable>
- Specified by:
- getTypein interface- TypedMessageBodyWriter<Writable>
- Returns:
- The body type.
 
- 
isBlockingpublic 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 interface- MessageBodyWriter<Writable>
- Returns:
- Whether this writer may block
 
- 
writeTopublic void writeTo(Argument<Writable> type, MediaType mediaType, Writable object, MutableHeaders outgoingHeaders, OutputStream outputStream) throws CodecException Description copied from interface:MessageBodyWriterWrites an object to the given output stream.- Specified by:
- writeToin interface- MessageBodyWriter<Writable>
- Parameters:
- type- The type
- mediaType- The media type
- object- The object to write
- outgoingHeaders- The HTTP headers
- outputStream- The output stream
- Throws:
- CodecException- If an error occurs decoding
 
- 
readChunkedpublic Publisher<? extends Writable> readChunked(Argument<Writable> type, MediaType mediaType, Headers httpHeaders, Publisher<ByteBuffer<?>> input) - Specified by:
- readChunkedin interface- ChunkedMessageBodyReader<Writable>
 
- 
readpublic Writable read(Argument<Writable> type, MediaType mediaType, Headers httpHeaders, ByteBuffer<?> byteBuffer) throws CodecException Description copied from interface:MessageBodyReaderReads an object from the given byte buffer.- Specified by:
- readin interface- MessageBodyReader<Writable>
- Parameters:
- type- The type being decoded.
- mediaType- The media type, can be- null
- httpHeaders- The HTTP headers
- byteBuffer- The byte buffer
- Returns:
- The read object or null
- Throws:
- CodecException- If an error occurs decoding
 
- 
readpublic Writable read(Argument<Writable> type, MediaType mediaType, Headers httpHeaders, InputStream inputStream) throws CodecException Description copied from interface:MessageBodyReaderReads an object from the given byte buffer.- Specified by:
- readin interface- MessageBodyReader<Writable>
- Parameters:
- type- The type being decoded.
- mediaType- The media type, can be- null
- httpHeaders- The HTTP headers
- inputStream- The input stream
- Returns:
- The read object or null
- Throws:
- CodecException- If an error occurs decoding
 
- 
writePiece@NonNull public @NonNull CloseableByteBody writePiece(@NonNull @NonNull ByteBodyFactory bodyFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull HttpResponse<?> response, @NonNull @NonNull Argument<Writable> type, @NonNull @NonNull MediaType mediaType, Writable object) throws CodecException Description copied from interface:ResponseBodyWriterWrite a piece of a larger response, e.g. when writing a Publisher or a part of a multipart response. In this case, response headers cannot be modified.- Specified by:
- writePiecein interface- ResponseBodyWriter<Writable>
- Parameters:
- bodyFactory- The buffer factory
- request- The request
- response- The response this piece is part of
- type- The type of this piece
- mediaType- The media type of this piece
- object- The piece to write
- Returns:
- The response bytes
- Throws:
- CodecException- If an error occurs encoding
 
 
-