com.univocity.api.statistics
Class DownloadListener

java.lang.Object
  extended by com.univocity.api.statistics.DataTransferListener<UrlReaderProvider,File,DownloadStatistics>
      extended by com.univocity.api.statistics.DownloadListener
All Implemented Interfaces:
DataTransfer<UrlReaderProvider,File>, Iterable<DownloadStatistics>

public abstract class DownloadListener
extends DataTransferListener<UrlReaderProvider,File,DownloadStatistics>

A listener of active downloads from remote locations into local files. Updates on the progress of each individual download are sent to the user on the dataDownloaded(DownloadStatistics, boolean) method. By default, updates to an individual download are sent every 250 ms, and immediately in case the download completes or is aborted.

Author:
uniVocity Software Pty Ltd - dev@univocity.com
See Also:
DataTransferListener, DownloadStatistics, DataTransferStatistics

Constructor Summary
DownloadListener()
          Creates a default download list that invokes the dataDownloaded(DownloadStatistics, boolean) method after at least 250ms have elapsed since the last call has been made for the same download process.
DownloadListener(long notificationInterval)
          Creates download list that invokes the dataDownloaded(DownloadStatistics, boolean) method after a given interval has elapsed since the last call has been made for the same download process.
 
Method Summary
protected abstract  void dataDownloaded(DownloadStatistics status, boolean lastNotification)
          Notifies of an update on the status of a download process.
protected  DownloadStatistics newDataTransfer(UrlReaderProvider source, long totalSize, File target)
          Creates a a new DataTransfer
 void setUnit(String unitDescription, long unitDivisor)
          Defines a description of the unit of data being transferred and updates the unit divisor to amounts will be returned taking into account the division of the totals by the given divisor.
 
Methods inherited from class com.univocity.api.statistics.DataTransferListener
aborted, completed, getActiveTransfers, isAborted, isRunning, isStarted, iterator, size, started, transferred
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadListener

public DownloadListener()
Creates a default download list that invokes the dataDownloaded(DownloadStatistics, boolean) method after at least 250ms have elapsed since the last call has been made for the same download process.


DownloadListener

public DownloadListener(long notificationInterval)
Creates download list that invokes the dataDownloaded(DownloadStatistics, boolean) method after a given interval has elapsed since the last call has been made for the same download process.

Parameters:
notificationInterval - how often, in milliseconds, the dataDownloaded(DownloadStatistics, boolean) should be invoked for each individual download process in this list
Method Detail

newDataTransfer

protected final DownloadStatistics newDataTransfer(UrlReaderProvider source,
                                                   long totalSize,
                                                   File target)
Description copied from class: DataTransferListener
Creates a a new DataTransfer

Specified by:
newDataTransfer in class DataTransferListener<UrlReaderProvider,File,DownloadStatistics>
Parameters:
source - where the data will be transferred from
totalSize - the total size of the data to be transferred
target - the target where the data will be transferred to
Returns:
a new DataTransfer that will transfer data of size totalSize from source to target

dataDownloaded

protected abstract void dataDownloaded(DownloadStatistics status,
                                       boolean lastNotification)
Notifies of an update on the status of a download process.

Parameters:
status - an object with statistics and information about the download and its progress
lastNotification - a flag indicating whether this notification is the last one (i.e. the download completed or was aborted due to an error)

setUnit

public void setUnit(String unitDescription,
                    long unitDivisor)
Defines a description of the unit of data being transferred and updates the unit divisor to amounts will be returned taking into account the division of the totals by the given divisor. This allows you to convert totals accumulated as bytes into kilobytes (unitDivisor = 1024) or megabytes (unitDivisor = 1024*1024) for example.

Parameters:
unitDescription - the description of what unit of data is being transferred
unitDivisor - the divisor to be applied over the totals accumulated by this class, so that the units


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.