Interface Downloader
-
- All Superinterfaces:
java.lang.AutoCloseable
public interface Downloader extends java.lang.AutoCloseableSome sort of downloader for files.Handles fetching strings and binary content from remotes as well.
Access may be cached.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDownloader.ResolveModeA mode to control usage of any potential locale cache
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.nio.file.PathbaseDir()Get the base directory used for this downloader.voidclose()java.util.concurrent.CompletableFuture<ResolutionResult<java.nio.file.Path>>download(java.net.URL source, java.lang.String destination)Download a file to the provided relative location.java.util.concurrent.CompletableFuture<ResolutionResult<java.nio.file.Path>>downloadAndValidate(java.net.URL source, java.lang.String destination, HashAlgorithm algorithm, java.lang.String hash)java.util.concurrent.CompletableFuture<ResolutionResult<byte[]>>readBytes(java.net.URL source, java.lang.String relativePath)Read the contents ofsourceas abyte[].java.util.concurrent.CompletableFuture<ResolutionResult<byte[]>>readBytesAndValidate(java.net.URL source, java.lang.String relativePath, HashAlgorithm algorithm, java.lang.String hash)Read the contents ofsourceas abyte[].java.util.concurrent.CompletableFuture<ResolutionResult<java.lang.String>>readString(java.net.URL source, java.lang.String relativePath)Read the contents ofsourceas aString.java.util.concurrent.CompletableFuture<ResolutionResult<java.lang.String>>readStringAndValidate(java.net.URL source, java.lang.String relativePath, HashAlgorithm algorithm, java.lang.String hash)Read the contents ofsourceas aString.DownloaderwithBaseDir(java.nio.file.Path override)Return a new downloader with a new base directory, but sharing this downloader's resources.
-
-
-
Method Detail
-
baseDir
java.nio.file.Path baseDir()
Get the base directory used for this downloader.- Returns:
- the base directory
-
withBaseDir
Downloader withBaseDir(java.nio.file.Path override)
Return a new downloader with a new base directory, but sharing this downloader's resources.Closing the returned downloader must not have any effect on this instance.
- Parameters:
override- the new base directory- Returns:
- a derived downloader
-
readString
java.util.concurrent.CompletableFuture<ResolutionResult<java.lang.String>> readString(java.net.URL source, java.lang.String relativePath)
Read the contents ofsourceas aString.Encoding will be determined based on response headers, defaulting to UTF-8.
- Parameters:
source- the URL to download fromrelativePath- the location to use as a cache key for the result- Returns:
- a future providing the completed result
-
readStringAndValidate
java.util.concurrent.CompletableFuture<ResolutionResult<java.lang.String>> readStringAndValidate(java.net.URL source, java.lang.String relativePath, HashAlgorithm algorithm, java.lang.String hash)
Read the contents ofsourceas aString.The downloaded content and any cached information will be validated against the provided hash.
- Parameters:
source- the URL to download fromrelativePath- the location to use as a cache key for the resultalgorithm- the hash algorithm to test withhash- the expected hash, as a string of hex digits- Returns:
- a future providing the resolved result
-
readBytes
java.util.concurrent.CompletableFuture<ResolutionResult<byte[]>> readBytes(java.net.URL source, java.lang.String relativePath)
Read the contents ofsourceas abyte[].- Parameters:
source- the URL to download fromrelativePath- the location to use as a cache key for the result- Returns:
- a future providing the completed result
-
readBytesAndValidate
java.util.concurrent.CompletableFuture<ResolutionResult<byte[]>> readBytesAndValidate(java.net.URL source, java.lang.String relativePath, HashAlgorithm algorithm, java.lang.String hash)
Read the contents ofsourceas abyte[].The downloaded content and any cached information will be validated against the provided hash.
- Parameters:
source- the URL to download fromrelativePath- the location to use as a cache key for the resultalgorithm- the hash algorithm to test withhash- the expected hash, as a string of hex digits- Returns:
- a future providing the resolved result
-
download
java.util.concurrent.CompletableFuture<ResolutionResult<java.nio.file.Path>> download(java.net.URL source, java.lang.String destination)
Download a file to the provided relative location.If the file already exists, it may not be overwritten, depending on the downloader's caching policy.
- Parameters:
source- the URL to download from.destination- a relative path to download to- Returns:
- a future returning the downloaded patch once a download is complete
-
downloadAndValidate
java.util.concurrent.CompletableFuture<ResolutionResult<java.nio.file.Path>> downloadAndValidate(java.net.URL source, java.lang.String destination, HashAlgorithm algorithm, java.lang.String hash)
-
close
void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
-