Class StreamedFile

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

public class StreamedFile extends Object implements FileCustomizableResponseType
A special type for streaming an InputStream representing a file or resource.
Since:
1.0
  • Constructor Details

    • StreamedFile

      public StreamedFile(InputStream inputStream, io.micronaut.http.MediaType mediaType)
      Parameters:
      inputStream - The input stream
      mediaType - The media type of the content
    • StreamedFile

      public StreamedFile(InputStream inputStream, io.micronaut.http.MediaType mediaType, long lastModified)
      Parameters:
      inputStream - The input stream
      mediaType - The media type of the content
      lastModified - The last modified date
    • StreamedFile

      public StreamedFile(InputStream inputStream, io.micronaut.http.MediaType mediaType, long lastModified, long contentLength)
      Parameters:
      inputStream - The input stream
      mediaType - The media type of the content
      lastModified - The last modified date
      contentLength - the content length
    • StreamedFile

      public StreamedFile(URL url)
      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 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 io.micronaut.http.MediaType getMediaType()
      Specified by:
      getMediaType in interface io.micronaut.http.body.MediaTypeProvider
    • getInputStream

      public InputStream getInputStream()
      Returns:
      The stream used to retrieve data for the file
    • attach

      public StreamedFile 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 StreamedFile instance
    • process

      public void process(io.micronaut.http.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