Package io.micronaut.http.server.body
Class SystemFileBodyWriter
java.lang.Object
io.micronaut.http.server.body.SystemFileBodyWriter
- All Implemented Interfaces:
MessageBodyWriter<SystemFile>
,ResponseBodyWriter<SystemFile>
@Singleton
@Internal
public final class SystemFileBodyWriter
extends Object
implements ResponseBodyWriter<SystemFile>
Body writer for
SystemFile
s.- Since:
- 4.0.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionprotected final HttpServerConfiguration.FileTypeHandlerConfiguration
-
Constructor Summary
ConstructorDescriptionSystemFileBodyWriter
(HttpServerConfiguration.FileTypeHandlerConfiguration configuration, ExecutorService ioExecutor) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
handleIfModifiedAndHeaders
(HttpRequest<?> request, MutableHttpResponse<?> response, FileCustomizableResponseType systemFile, MutableHttpResponse<?> nettyResponse) protected ByteBodyHttpResponse<?>
notModified
(ByteBodyFactory bodyFactory, MutableHttpResponse<?> originalResponse) protected void
setDateAndCacheHeaders
(MutableHttpResponse response, long lastModified) protected void
setDateHeader
(MutableHttpResponse response) write
(@NonNull ByteBodyFactory bodyFactory, HttpRequest<?> request, @NonNull MutableHttpResponse<SystemFile> httpResponse, @NonNull Argument<SystemFile> type, @NonNull MediaType mediaType, SystemFile object) Writes an object as aByteBodyHttpResponse
.write
(@NonNull ByteBodyFactory bodyFactory, HttpRequest<?> request, MutableHttpResponse<SystemFile> response, SystemFile systemFile) writePiece
(@NonNull ByteBodyFactory bodyFactory, @NonNull HttpRequest<?> request, @NonNull HttpResponse<?> response, @NonNull Argument<SystemFile> type, @NonNull MediaType mediaType, SystemFile object) Write a piece of a larger response, e.g.writePiece
(@NonNull ByteBodyFactory bodyFactory, SystemFile object) void
writeTo
(Argument<SystemFile> type, MediaType mediaType, SystemFile file, MutableHeaders outgoingHeaders, OutputStream outputStream) Writes an object to the given output stream.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.MessageBodyWriter
createSpecific, isBlocking, isWriteable, writeTo
-
Field Details
-
configuration
-
-
Constructor Details
-
SystemFileBodyWriter
public SystemFileBodyWriter(HttpServerConfiguration.FileTypeHandlerConfiguration configuration, @Named("blocking") ExecutorService ioExecutor)
-
-
Method Details
-
writeTo
public void writeTo(Argument<SystemFile> type, MediaType mediaType, SystemFile file, MutableHeaders outgoingHeaders, OutputStream outputStream) throws CodecException Description copied from interface:MessageBodyWriter
Writes an object to the given output stream.- Specified by:
writeTo
in interfaceMessageBodyWriter<SystemFile>
- Parameters:
type
- The typemediaType
- The media typefile
- The object to writeoutgoingHeaders
- The HTTP headersoutputStream
- The output stream- Throws:
CodecException
- If an error occurs decoding
-
write
public ByteBodyHttpResponse<?> write(@NonNull @NonNull ByteBodyFactory bodyFactory, HttpRequest<?> request, @NonNull @NonNull MutableHttpResponse<SystemFile> httpResponse, @NonNull @NonNull Argument<SystemFile> type, @NonNull @NonNull MediaType mediaType, SystemFile object) throws CodecException Description copied from interface:ResponseBodyWriter
Writes an object as aByteBodyHttpResponse
.- Specified by:
write
in interfaceResponseBodyWriter<SystemFile>
- Parameters:
bodyFactory
- 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
-
write
public ByteBodyHttpResponse<?> write(@NonNull @NonNull ByteBodyFactory bodyFactory, HttpRequest<?> request, MutableHttpResponse<SystemFile> response, SystemFile systemFile) throws CodecException - Throws:
CodecException
-
writePiece
public CloseableByteBody writePiece(@NonNull @NonNull ByteBodyFactory bodyFactory, @NonNull @NonNull HttpRequest<?> request, @NonNull @NonNull HttpResponse<?> response, @NonNull @NonNull Argument<SystemFile> type, @NonNull @NonNull MediaType mediaType, SystemFile object) Description copied from interface:ResponseBodyWriter
Write 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:
writePiece
in interfaceResponseBodyWriter<SystemFile>
- Parameters:
bodyFactory
- The buffer factoryrequest
- The requestresponse
- The response this piece is part oftype
- The type of this piecemediaType
- The media type of this pieceobject
- The piece to write- Returns:
- The response bytes
-
writePiece
@NonNull public @NonNull CloseableByteBody writePiece(@NonNull @NonNull ByteBodyFactory bodyFactory, SystemFile object) -
handleIfModifiedAndHeaders
protected boolean handleIfModifiedAndHeaders(HttpRequest<?> request, MutableHttpResponse<?> response, FileCustomizableResponseType systemFile, MutableHttpResponse<?> nettyResponse) -
setDateAndCacheHeaders
- Parameters:
response
- The Http responselastModified
- The last modified
-
setDateHeader
- Parameters:
response
- The Http response
-
notModified
protected ByteBodyHttpResponse<?> notModified(ByteBodyFactory bodyFactory, MutableHttpResponse<?> originalResponse)
-