Class FileResponse

  • Direct Known Subclasses:
    RestFileResponse, ServletFileResponse

    public abstract class FileResponse
    extends Object
    Centralizing the code which permits to send a file, and if necessary or asked to send it partially.
    Author:
    Yohann Chastagnier
    • Method Detail

      • encodeInlineFilenameAsUtf8

        public static String encodeInlineFilenameAsUtf8​(String filename)
        Encodes the content disposition with inline filename as UTF8.
        Parameters:
        filename - the filename to encode.
        Returns:
        the encoded
      • encodeAttachmentFilenameAsUtf8

        public static String encodeAttachmentFilenameAsUtf8​(String filename)
        Encodes the content disposition with attachment filename as UTF8.
        Parameters:
        filename - the filename to encode.
        Returns:
        the encoded
      • fromRest

        public static RestFileResponse fromRest​(javax.servlet.http.HttpServletRequest request,
                                                javax.servlet.http.HttpServletResponse response)
        Initializing the file response context.
        Parameters:
        request - the current request.
        response - the current response.
        Returns:
        the initialized file response.
      • fromServlet

        public static ServletFileResponse fromServlet​(javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response)
        Initializing the file response context.
        Parameters:
        request - the current request.
        response - the current response.
        Returns:
        the initialized file response.
      • forceFileId

        public FileResponse forceFileId​(String fileId)
        Forces the file identifier.
        If not forced, the absolute path of the file into Base64 is computed.
        Parameters:
        fileId - the file identifier.
        Returns:
        itself.
      • forceFileName

        public FileResponse forceFileName​(String fileName)
        Forces the file name into the response.
        If not forced, the file name is computed from the file itself.
        Even if a file name has been forced, if the request contains into headers a valuated forceFileName parameter, the file name from the request is taken into account.
        Parameters:
        fileName - the file name to set.
        Returns:
        itself.
      • forceMimeType

        public FileResponse forceMimeType​(String mimeType)
        Forces the mime type of the response.
        If not forced, the mime type is computed from the file itself.
        Even if a mime type has been forced, if the request contains into headers a valuated forceMimeType parameter, the mime type from the request is taken into account.
        Parameters:
        mimeType - the mime type to set.
        Returns:
        itself.
      • forceCharacterEncoding

        public FileResponse forceCharacterEncoding​(String forcedCharacterEncoding)
        Forces the character encoding of the response.
        Parameters:
        forcedCharacterEncoding - the character encoding to set.
        Returns:
        itself.
      • noCache

        public FileResponse noCache()
        Sets into response that no cache MUST be handled.
        Returns:
        itself.