Class DownloadUtil

java.lang.Object
ubic.gemma.web.controller.util.DownloadUtil

@Component public class DownloadUtil extends Object
Utility class for providing Path as downloads.

If available, Tomcat sendfile is used.

Author:
poirigui
  • Constructor Details

    • DownloadUtil

      public DownloadUtil()
  • Method Details

    • download

      public void download(Path file, String contentType, @Nullable String contentEncoding, boolean downloadAsAttachment, @Nullable String downloadName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
      Provide a file download to the response.

      If available, Tomcat sendfile capability is used.

      If the file is not readable, a 404 error will be sent to the response.

      Parameters:
      file - the file to download from
      contentType - content type of the file to download, e.g. "application/pdf" or "text/plain", if the file is compressed, you may either serve it as-is using "application/octet-stream" or transparently decompressed by the client by setting contentEncoding appropriately.
      contentEncoding - content encoding of the file to download, set this only to provide on-the-fly decompression by the client.
      downloadAsAttachment - if true, the file will be downloaded as an attachment, otherwise it will be served directly
      downloadName - this string will be used as a download name for the downloaded file. If null, the filesystem name of the file will be used. This does nothing if downloadAsAttachment is false. It is not escaped, so you should make sure that the filename is safe to use in an HTTP header.
      Throws:
      IOException - if an error occurred during the file transmission