Package org.aktin.broker.download
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 Summary
Constructors Constructor Description DownloadManager()DownloadManager(Path tempDir) -
Method Summary
Modifier and Type Method Description voidcleanupExpired()Cleanup expired downloads.DownloadcreateDataSourceDownload(javax.activation.DataSource ds, String name)Create download to a given local path.DownloadcreateTemporaryFile(String mediaType, String name)Create a temporary file for download.Downloadget(UUID id)Retrieve a download for the given id.voidsetTempDirectory(Path dir)Set the directory where temporary downloads will be created and stored before they expire.
-
Constructor Details
-
DownloadManager
public DownloadManager() -
DownloadManager
- Throws:
IOException
-
-
Method Details
-
setTempDirectory
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
Retrieve a download for the given id. Non-existing and expired downloads will returnnull.- Parameters:
id- id for the download to be retrieved- Returns:
- download or
nullif not found or expired - Throws:
IOException- IO error
-
createDataSourceDownload
Create download to a given local path. The path will not be deleted once the download expires.- Parameters:
ds- data source for downloadname- optional name for download- Returns:
- Download
-
createTemporaryFile
Create a temporary file for download. Once the download expires, the file will be deleted.- Parameters:
mediaType- media type for the downloadname- optional file name for the download,nullto omit- Returns:
- download
- Throws:
IOException- IO error
-
cleanupExpired
Cleanup expired downloads.- Throws:
IOException- io error
-