public interface Downloader
| Modifier and Type | Method and Description |
|---|---|
java.io.InputStream |
downloadAndStream(java.net.URL url,
ProgressIndicator indicator)
Gets a stream associated with the content at the given URL.
|
void |
downloadFully(java.net.URL url,
java.io.File target,
java.lang.String checksum,
ProgressIndicator indicator)
Downloads the content at the given URL to the given file.
|
java.nio.file.Path |
downloadFully(java.net.URL url,
ProgressIndicator indicator)
Downloads the content at the given URL to a temporary file and returns a handle to that file.
|
default void |
downloadFullyWithCaching(java.net.URL url,
java.io.File target,
java.lang.String checksum,
ProgressIndicator indicator)
Downloads the content at the given URL to the given file, using caching techniques if
possible.
|
static java.lang.String |
hash(java.io.InputStream in,
long fileSize,
ProgressIndicator progress)
Hash the given input stream.
|
@Nullable
java.io.InputStream downloadAndStream(@NonNull
java.net.URL url,
@NonNull
ProgressIndicator indicator)
throws java.io.IOException
url - The URL to fetch.indicator - Facility for showing download progress and logging.null if the
download is cancelled.java.io.IOException@Nullable
java.nio.file.Path downloadFully(@NonNull
java.net.URL url,
@NonNull
ProgressIndicator indicator)
throws java.io.IOException
url - The URL to fetch.indicator - Facility for showing download progress and logging.null if the download is cancelled.java.io.IOExceptionvoid downloadFully(@NonNull
java.net.URL url,
@NonNull
java.io.File target,
@Nullable
java.lang.String checksum,
@NonNull
ProgressIndicator indicator)
throws java.io.IOException
For example, in case of HTTP connections, calling this method may be equivalent to adding "Cache-Control: no-cache" and "Pragma: no-cache" headers to the request, thus instructing the network facilities that no caching is expected to take place (e.g., on proxy servers).
url - The URL to fetch.target - The location to download to.checksum - If specified, first check target to see if the given checksum matches
the existing file. If so, returns immediately.indicator - Facility for showing download progress and logging.java.io.IOExceptiondefault void downloadFullyWithCaching(@NonNull
java.net.URL url,
@NonNull
java.io.File target,
@Nullable
java.lang.String checksum,
@NonNull
ProgressIndicator indicator)
throws java.io.IOException
Note that calling this method does not guarantee caching or a better performance: it is an
implementation detail how exactly this hint is used. For example, when checking for software
updates availability, the caller will know that no caching must be used, so it should not
call this method, and call downloadFully(java.net.URL, com.android.repository.api.ProgressIndicator) instead. On the other hand, for a large
download which is not expected to change on the original server, the caller typically would
not mind against intrinsic optimizations and caching, so in that case it should call this
method.
url - The URL to fetch.target - The location to download to.checksum - If specified, first check target to see if the given checksum matches
the existing file. If so, returns immediately.indicator - Facility for showing download progress and logging.java.io.IOException@NonNull
static java.lang.String hash(@NonNull
java.io.InputStream in,
long fileSize,
@NonNull
ProgressIndicator progress)
throws java.io.IOException
in - The stream to hash. It will be fully consumed but not closed.fileSize - The expected length of the stream, for progress display purposes.progress - The indicator will be updated with the expected completion fraction.java.io.IOException - IF there's a problem reading from the stream.