Class SystemFile

java.lang.Object
io.micronaut.http.server.types.files.SystemFile
All Implemented Interfaces:
MediaTypeProvider, CustomizableResponseType, FileCustomizableResponseType

public class SystemFile extends Object implements FileCustomizableResponseType
Used as the return value of a route execution to send File instances to the client. More efficient than StreamedFile.
Since:
1.1.0
Author:
James Kleeh
  • Constructor Details

    • SystemFile

      public SystemFile(File file)
      Parameters:
      file - The file to respond with
    • SystemFile

      public SystemFile(File file, MediaType mediaType)
      Parameters:
      file - The file to respond with
      mediaType - The content type of the response
  • Method Details

    • getLastModified

      public long getLastModified()
      Specified by:
      getLastModified in interface FileCustomizableResponseType
      Returns:
      The last modified date of the file
    • getLength

      public long getLength()
      Specified by:
      getLength in interface FileCustomizableResponseType
      Returns:
      The length of the file
    • getMediaType

      public MediaType getMediaType()
      Specified by:
      getMediaType in interface MediaTypeProvider
      Returns:
      The media type of the object.
    • getFile

      public File getFile()
      Returns:
      The file
    • attach

      public SystemFile attach()
      Sets the file to be downloaded as an attachment. The file name is set in the Content-Disposition header.
      Returns:
      The same SystemFile instance
    • attach

      public SystemFile attach(String attachmentName)
      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 SystemFile instance
    • process

      public void process(MutableHttpResponse response)
      Description copied from interface: CustomizableResponseType
      Modify the response before it is written to the client.
      Specified by:
      process in interface CustomizableResponseType
      Parameters:
      response - The response to modify