Class DownloadHelper


  • public class DownloadHelper
    extends Object
    Helper class related to the download service.
    Since:
    7.3
    • Method Detail

      • parseRange

        public static ByteRange parseRange​(String range,
                                           long length)
        Parses a byte range.
        Parameters:
        range - the byte range as a string
        length - the file length
        Returns:
        the byte range, or null if it couldn't be parsed.
      • getRFC2231ContentDisposition

        public static String getRFC2231ContentDisposition​(javax.servlet.http.HttpServletRequest request,
                                                          String filename)
        Generates a Content-Disposition string based on the servlet request for a given filename.

        The value follows RFC2231.

        Parameters:
        request - the http servlet request
        filename - the filename
        Returns:
        a full string to set as value of a Content-Disposition header
      • getRFC2231ContentDisposition

        public static String getRFC2231ContentDisposition​(javax.servlet.http.HttpServletRequest request,
                                                          String filename,
                                                          Boolean inline)
        Generates a Content-Disposition string for a given filename.

        The value follows RFC2231.

        Parameters:
        request - the http servlet request
        filename - the filename
        inline - how to set the content disposition; TRUE for inline, FALSE for attachment, or null to detect from inline request parameter or attribute
        Returns:
        a full string to set as value of a Content-Disposition header
        Since:
        7.10
      • getContentTypeHeader

        public static String getContentTypeHeader​(Blob blob)
        Gets the Content-Type header for the given blob, per RFC 2616.

        For example application/pdf or text/plain; charset=ISO-8859-1.

        Parameters:
        blob - the blob
        Returns:
        the header, or null if the blob has no content type information
        Since:
        11.1
      • isClientAbortError

        public static boolean isClientAbortError​(Throwable t)
      • logClientAbort

        public static void logClientAbort​(Throwable t)
      • handleClientDisconnect

        public static void handleClientDisconnect​(IOException e)
                                           throws IOException
        Re-throws the passed exception except if it corresponds to a client disconnect, for which logging doesn't bring us anything.
        Parameters:
        e - the original exception
        Throws:
        IOException - if this is not a client disconnect