Class PreparedDownload

  • All Implemented Interfaces:
    Serializable

    public class PreparedDownload
    extends Object
    implements Serializable
    Prepared download means a download in two time.

    In a first time, from an AJAX request, a download is prepared and saved into a temporary file.
    A JSON response is returned containing an object with the attribute preparedDownloadUrl.

    In a second time, the prepared file is downloaded from preparedDownloadUrl and deleted from temporary files.

    The main objective of that is to get more control on UI in order to manage user navigation on file download.

    Author:
    silveryocha
    See Also:
    Serialized Form
    • Constructor Detail

      • PreparedDownload

        public PreparedDownload​(String fileName,
                                String contentType)
    • Method Detail

      • getPreparedDownloadToPerform

        public static Optional<PreparedDownload> getPreparedDownloadToPerform​(javax.servlet.http.HttpServletRequest request,
                                                                              String fileName,
                                                                              String contentType)
        Gets a new PreparedDownload instance if PREPARED_DOWNLOAD is detected into request parameters.
        Parameters:
        request - the request.
        fileName - the filename which will be downloaded.
        contentType - the content type of the content which will be downloaded.
        Returns:
        an optional PreparedDownload instance.
      • getFrom

        public static PreparedDownload getFrom​(javax.servlet.http.HttpServletRequest request)
        Gets from the given request the PreparedDownload instance registered into the session if any.
        Parameters:
        request - the request.
        Returns:
        a PreparedDownload instance.
      • getWriter

        public Writer getWriter​(String charset)
                         throws IOException
        Gets the writer into which the content MUST be written.
        Parameters:
        charset - the character encoding to set to the writer.
        Returns:
        a Writer instance.
        Throws:
        IOException - on technical error.
      • sendDetails

        public void sendDetails​(javax.servlet.http.HttpServletResponse response)
                         throws IOException
        Sends the identifier into the response and put into sessions cache this PreparedDownload instance.
        Parameters:
        response - the response.
        Throws:
        IOException - on technical error.
      • sendTo

        public void sendTo​(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
        Sends the prepared file into response with a download context.

        After a successful or an unsuccessful send, the file is deleted.

        Parameters:
        request - a request.
        response - a response.