Class DownloadManager

java.lang.Object
org.aktin.broker.download.DownloadManager

@Singleton
public class DownloadManager
extends Object
Creates and manages downloads which expire after a predefined amount of time. This class is useful to separate authentication (needed to request downloads) from the actual download. The browser does not send authentication headers (e.g. bearer token) to download links.
Author:
R.W.Majeed
  • Constructor Details

    • DownloadManager

      public DownloadManager()
    • DownloadManager

      public DownloadManager​(Path tempDir) throws IOException
      Throws:
      IOException
  • Method Details

    • setTempDirectory

      public void setTempDirectory​(Path dir) throws IOException
      Set the directory where temporary downloads will be created and stored before they expire. If the specified path does not exist, the directory will be created.
      Parameters:
      dir - path to store temporary download files
      Throws:
      IOException - IO error because directories could not be created
    • get

      public Download get​(UUID id) throws IOException
      Retrieve a download for the given id. Non-existing and expired downloads will return null.
      Parameters:
      id - id for the download to be retrieved
      Returns:
      download or null if not found or expired
      Throws:
      IOException - IO error
    • createDataSourceDownload

      public Download createDataSourceDownload​(javax.activation.DataSource ds, String name)
      Create download to a given local path. The path will not be deleted once the download expires.
      Parameters:
      ds - data source for download
      name - optional name for download
      Returns:
      Download
    • createTemporaryFile

      public Download createTemporaryFile​(String mediaType, String name) throws IOException
      Create a temporary file for download. Once the download expires, the file will be deleted.
      Parameters:
      mediaType - media type for the download
      name - optional file name for the download, null to omit
      Returns:
      download
      Throws:
      IOException - IO error
    • cleanupExpired

      public void cleanupExpired() throws IOException
      Cleanup expired downloads.
      Throws:
      IOException - io error