Class StreamedFile
java.lang.Object
io.micronaut.http.server.types.files.StreamedFile
- All Implemented Interfaces:
MediaTypeProvider
,CustomizableResponseType
,FileCustomizableResponseType
A special type for streaming an
InputStream
representing a file or resource.- Since:
- 1.0
- Author:
- James Kleeh
-
Field Summary
Fields inherited from interface io.micronaut.http.server.types.files.FileCustomizableResponseType
ATTACHMENT_HEADER
-
Constructor Summary
ConstructorDescriptionStreamedFile
(InputStream inputStream, MediaType mediaType) StreamedFile
(InputStream inputStream, MediaType mediaType, long lastModified) StreamedFile
(InputStream inputStream, MediaType mediaType, long lastModified, long contentLength) StreamedFile
(URL url) Immediately opens a connection to the given URL to retrieve data about the connection, including the input stream. -
Method Summary
Modifier and TypeMethodDescriptionSets the file to be downloaded as an attachment.long
long
void
process
(MutableHttpResponse<?> response) Modify the response before it is written to the client.
-
Constructor Details
-
StreamedFile
- Parameters:
inputStream
- The input streammediaType
- The media type of the content
-
StreamedFile
- Parameters:
inputStream
- The input streammediaType
- The media type of the contentlastModified
- The last modified date
-
StreamedFile
public StreamedFile(InputStream inputStream, MediaType mediaType, long lastModified, long contentLength) - Parameters:
inputStream
- The input streammediaType
- The media type of the contentlastModified
- The last modified datecontentLength
- the content length
-
StreamedFile
Immediately opens a connection to the given URL to retrieve data about the connection, including the input stream.- Parameters:
url
- The URL to resource
-
-
Method Details
-
getLastModified
public long getLastModified()- Specified by:
getLastModified
in interfaceFileCustomizableResponseType
- Returns:
- The last modified date of the file
-
getLength
public long getLength()- Specified by:
getLength
in interfaceFileCustomizableResponseType
- Returns:
- The length of the file
-
getMediaType
- Specified by:
getMediaType
in interfaceMediaTypeProvider
- Returns:
- The media type of the object.
-
getInputStream
- Returns:
- The stream used to retrieve data for the file
-
attach
Sets the file to be downloaded as an attachment. The name is set in the Content-Disposition header.- Parameters:
attachmentName
- The attachment name.- Returns:
- The same StreamedFile instance
-
process
Description copied from interface:CustomizableResponseType
Modify the response before it is written to the client.- Specified by:
process
in interfaceCustomizableResponseType
- Parameters:
response
- The response to modify
-