Class BinaryFileServlet.DownloadTicket

  • All Implemented Interfaces:
    java.io.Serializable
    Enclosing class:
    BinaryFileServlet

    public static class BinaryFileServlet.DownloadTicket
    extends java.lang.Object
    implements java.io.Serializable
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DownloadTicket​(java.io.File file)
      Builds a new download ticket for the specified file.
      DownloadTicket​(java.io.File file, java.lang.String contentType)
      Builds a new download ticket for the specified file.
      DownloadTicket​(java.io.File file, java.lang.String contentType, java.lang.String filename)
      Builds a new download ticket for the specified file.
      DownloadTicket​(java.io.File file, java.lang.String contentType, java.lang.String filename, boolean forceDownload)
      Builds a new download ticket for the specified file.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void sendToDownloadUrl​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Redirect current request to the download URL of the file specified by this ticket.
      void setContentType​(java.lang.String contentType)
      Set the content type to use for this download.
      void setDeleteFileAfterDelivery​(boolean deleteFileAfterDelivery)
      Set whether the file should be deleted after the delivery to the client.
      void setFilename​(java.lang.String filename)
      Set the filename to be displayed in the browser (content disposition/attachement)
      void setUsePragmaNoCache​(boolean usePragmaNoCache)
      Set whether to use HTTP header "Pragma", "no-cache".
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DownloadTicket

        public DownloadTicket​(java.io.File file)
        Builds a new download ticket for the specified file.
        Parameters:
        file - the file to send required.
      • DownloadTicket

        public DownloadTicket​(java.io.File file,
                              java.lang.String contentType)
        Builds a new download ticket for the specified file.
        Parameters:
        file - the file to send required.
        contentType - the content type to use (default is application/octet-stream)
      • DownloadTicket

        public DownloadTicket​(java.io.File file,
                              java.lang.String contentType,
                              java.lang.String filename)
        Builds a new download ticket for the specified file.
        Parameters:
        file - the file to send. required.
        contentType - the content type to use (default is application/octet-stream)
        filename - the filename to be displayed in the browser (content disposition/attachement), use alphanumeric or dash, do not use special characters.
      • DownloadTicket

        public DownloadTicket​(java.io.File file,
                              java.lang.String contentType,
                              java.lang.String filename,
                              boolean forceDownload)
        Builds a new download ticket for the specified file.
        Parameters:
        file - the file to send. required.
        contentType - the content type to use (default is application/octet-stream)
        filename - the filename to be displayed in the browser (content-disposition), use alphanumeric or dash, do not use special characters.
        forceDownload - if true force the download (ie add attachement, in content-disposition header)
    • Method Detail

      • setContentType

        public void setContentType​(java.lang.String contentType)
        Set the content type to use for this download.

        Default is application/octet-stream.

        Parameters:
        contentType - a content type such as "image/jpeg"
      • setFilename

        public void setFilename​(java.lang.String filename)
        Set the filename to be displayed in the browser (content disposition/attachement)

        Default value is null (no filename is sent to browser).

        Parameters:
        filename - a filename such as my-file.csv, use alphanumeric or dash, do not use special characters. or null to skip.
      • setUsePragmaNoCache

        public void setUsePragmaNoCache​(boolean usePragmaNoCache)
        Set whether to use HTTP header "Pragma", "no-cache".

        Default is false.

        Parameters:
        usePragmaNoCache - true to use pragma/nocache header, false otherwise.
      • setDeleteFileAfterDelivery

        public void setDeleteFileAfterDelivery​(boolean deleteFileAfterDelivery)
        Set whether the file should be deleted after the delivery to the client.

        Default is false.

        Parameters:
        deleteFileAfterDelivery - true to delete file after delivery, false to leave file as is.
      • sendToDownloadUrl

        public void sendToDownloadUrl​(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response)
                               throws java.io.IOException
        Redirect current request to the download URL of the file specified by this ticket.
        Parameters:
        request - current HttpServletRequest
        response - the response in which to write redirect headers
        Throws:
        java.io.IOException - the IO exception
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object