Class DownloadImpl

  • All Implemented Interfaces:
    Download

    class DownloadImpl
    extends java.lang.Object
    implements Download
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Cancels a download.
      java.io.InputStream createReadStream()
      Returns readable stream for current download or null if download failed.
      void delete()
      Deletes the downloaded file.
      java.lang.String failure()
      Returns download error if any.
      Page page()
      Get the page that the download belongs to.
      java.nio.file.Path path()
      Returns path to the downloaded file in case of successful download.
      void saveAs​(java.nio.file.Path path)
      Copy the download to a user-specified path.
      java.lang.String suggestedFilename()
      Returns suggested filename for this download.
      java.lang.String url()
      Returns downloaded url.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • initializer

        private final com.google.gson.JsonObject initializer
    • Constructor Detail

      • DownloadImpl

        DownloadImpl​(PageImpl page,
                     ArtifactImpl artifact,
                     com.google.gson.JsonObject initializer)
    • Method Detail

      • url

        public java.lang.String url()
        Description copied from interface: Download
        Returns downloaded url.
        Specified by:
        url in interface Download
      • suggestedFilename

        public java.lang.String suggestedFilename()
        Description copied from interface: Download
        Returns suggested filename for this download. It is typically computed by the browser from the Content-Disposition response header or the download attribute. See the spec on whatwg. Different browsers can use different logic for computing it.
        Specified by:
        suggestedFilename in interface Download
      • cancel

        public void cancel()
        Description copied from interface: Download
        Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations, download.failure() would resolve to "canceled".
        Specified by:
        cancel in interface Download
      • createReadStream

        public java.io.InputStream createReadStream()
        Description copied from interface: Download
        Returns readable stream for current download or null if download failed.
        Specified by:
        createReadStream in interface Download
      • delete

        public void delete()
        Description copied from interface: Download
        Deletes the downloaded file. Will wait for the download to finish if necessary.
        Specified by:
        delete in interface Download
      • failure

        public java.lang.String failure()
        Description copied from interface: Download
        Returns download error if any. Will wait for the download to finish if necessary.
        Specified by:
        failure in interface Download
      • page

        public Page page()
        Description copied from interface: Download
        Get the page that the download belongs to.
        Specified by:
        page in interface Download
      • path

        public java.nio.file.Path path()
        Description copied from interface: Download
        Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if necessary. The method throws when connected remotely.

        Note that the download's file name is a random GUID, use Download.suggestedFilename() to get suggested file name.

        Specified by:
        path in interface Download
      • saveAs

        public void saveAs​(java.nio.file.Path path)
        Description copied from interface: Download
        Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will wait for the download to finish if necessary.

        **Usage**

        
         download.saveAs(Paths.get("/path/to/save/at/", download.suggestedFilename()));
         
        Specified by:
        saveAs in interface Download
        Parameters:
        path - Path where the download should be copied.