Class FileDownloader

All Implemented Interfaces:
com.github.tadukoo.util.download.ProgressRBCWrapperListener, ImageObserver, MenuContainer, Serializable, Accessible

public class FileDownloader extends JPanel implements com.github.tadukoo.util.download.ProgressRBCWrapperListener
File Downloader is used to give a File Download option dialog to the user for them to be able to download files and watch the progress of the download(s).
Version:
Alpha v.0.3.3
Author:
Logan Ferree (Tadukoo)
See Also:
  • Field Details

    • overallProgressBar

      private final JProgressBar overallProgressBar
      The progress bar for all the files to be downloaded
    • singleProgressBar

      private final JProgressBar singleProgressBar
      The progress bar for the current file being downloaded
    • logger

      private final com.github.tadukoo.util.logger.EasyLogger logger
      The logger to use for logging problems
  • Constructor Details

    • FileDownloader

      public FileDownloader(Component parentComponent, com.github.tadukoo.util.logger.EasyLogger logger, Collection<com.github.tadukoo.util.tuple.Pair<String,String>> fileAddressAndPathPairs)
      Creates a new File Downloader, which will be an Option Dialog for the user from the given parent component
      Parameters:
      parentComponent - The Component used to launch this File Downloader
      logger - The logger to use for logging problems
      fileAddressAndPathPairs - Pairs of file URLs and local filepaths of files to be downloaded
  • Method Details

    • progressUpdate

      public void progressUpdate(double progress, long bytesSoFar, long expectedSize)
      This will be called by a ProgressReadableByteChannelWrapper as progress is made with it, so that this listener can handle the progress update tracking as desired
      Specified by:
      progressUpdate in interface com.github.tadukoo.util.download.ProgressRBCWrapperListener
      Parameters:
      progress - The current progress
      bytesSoFar - The amount of bytes read so far
      expectedSize - The expected total amount of bytes to be read
    • getFileSize

      private int getFileSize(URL url)
      Attempts to grab the file size for the file at the given URL. If it fails, a warning will be logged, but it will not error out and return -1
      Parameters:
      url - The URL the file is located at
      Returns:
      The size of the file in bytes, or -1 if we fail to retrieve it
    • loadFiles

      private void loadFiles(Collection<com.github.tadukoo.util.tuple.Pair<String,String>> fileAddressAndPathPairs) throws IOException
      Iterates over the given file address and filepath pairs to download the files as needed and updates the overall progress bar on the overall files progress.
      Parameters:
      fileAddressAndPathPairs - Pairs of file URLs and local filepaths for files to be downloaded
      Throws:
      IOException - If anything goes wrong in downloading files
    • loadFile

      private void loadFile(String address, String filepath) throws IOException
      If the file already exists at the given filepath, nothing happens. Otherwise, we download it from the given address, and progress will be updated by sending this as a ProgressRBCWrapperListener to the ProgressReadableByteChannelWrapper we use
      Parameters:
      address - The URL for the file to be downloaded
      filepath - The local filepath for the file
      Throws:
      IOException - If anything goes wrong in downloading the file