Class LocalFileAwareDownloader

  • All Implemented Interfaces:
    Downloader

    public class LocalFileAwareDownloader
    extends java.lang.Object
    implements Downloader
    Decorator around another Downloader that handles file:/// URLs. Such URLs can be used for testing.
    • Constructor Detail

      • LocalFileAwareDownloader

        public LocalFileAwareDownloader​(@NonNull
                                        Downloader delegate)
    • Method Detail

      • downloadAndStream

        @Nullable
        public java.io.InputStream downloadAndStream​(@NonNull
                                                     java.net.URL url,
                                                     @NonNull
                                                     ProgressIndicator indicator)
                                              throws java.io.IOException
        Description copied from interface: Downloader
        Gets a stream associated with the content at the given URL. This could be achieved by downloading the file completely, streaming it directly, or some combination.
        Specified by:
        downloadAndStream in interface Downloader
        Parameters:
        url - The URL to fetch.
        indicator - Facility for showing download progress and logging.
        Returns:
        An InputStream corresponding to the specified content, or null if the download is cancelled.
        Throws:
        java.io.IOException
      • downloadFully

        @Nullable
        public java.nio.file.Path downloadFully​(@NonNull
                                                java.net.URL url,
                                                @NonNull
                                                ProgressIndicator indicator)
                                         throws java.io.IOException
        Description copied from interface: Downloader
        Downloads the content at the given URL to a temporary file and returns a handle to that file.
        Specified by:
        downloadFully in interface Downloader
        Parameters:
        url - The URL to fetch.
        indicator - Facility for showing download progress and logging.
        Returns:
        The temporary file, or null if the download is cancelled.
        Throws:
        java.io.IOException
      • downloadFully

        public void downloadFully​(@NonNull
                                  java.net.URL url,
                                  @NonNull
                                  java.nio.file.Path target,
                                  @Nullable
                                  Checksum checksum,
                                  @NonNull
                                  ProgressIndicator indicator)
                           throws java.io.IOException
        Description copied from interface: Downloader
        Downloads the content at the given URL to the given file. Calling this method instructs the downloader to fetch the content from the original server and bypass any caches.

        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).

        Specified by:
        downloadFully in interface Downloader
        Parameters:
        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.
        Throws:
        java.io.IOException