cz.vity.freerapid.core.tasks
Class DownloadTask
java.lang.Object
org.jdesktop.swingworker.SwingWorker<T,V>
org.jdesktop.application.Task<T,V>
cz.vity.freerapid.core.tasks.CoreTask<Void,Long>
cz.vity.freerapid.core.tasks.DownloadTask
- All Implemented Interfaces:
- HttpFileDownloadTask, Runnable, Future<Void>
- Direct Known Subclasses:
- DownloadNewPluginsTask, RunCheckTask
public class DownloadTask
- extends CoreTask<Void,Long>
- implements HttpFileDownloadTask
- Author:
- Vity
Nested classes/interfaces inherited from class org.jdesktop.application.Task |
org.jdesktop.application.Task.BlockingScope, org.jdesktop.application.Task.InputBlocker |
Nested classes/interfaces inherited from class org.jdesktop.swingworker.SwingWorker |
org.jdesktop.swingworker.SwingWorker.StateValue |
Methods inherited from class org.jdesktop.application.Task |
addTaskListener, done, finished, getApplication, getContext, getDescription, getExecutionDuration, getInputBlocker, getMessage, getMessageDuration, getResourceMap, getTaskListeners, getTaskService, getTitle, getUserCanCancel, isPending, isProgressPropertyValid, isStarted, message, process, removeTaskListener, resourceName, setDescription, setInputBlocker, setMessage, setProgress, setProgress, setProgress, setTitle, setUserCanCancel |
Methods inherited from class org.jdesktop.swingworker.SwingWorker |
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, publish, removePropertyChangeListener, run, setProgress |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
client
protected HttpDownloadClient client
downloadFile
protected DownloadFile downloadFile
service
protected ShareDownloadService service
outputFile
protected File outputFile
storeFile
protected File storeFile
DownloadTask
public DownloadTask(org.jdesktop.application.Application application)
DownloadTask
public DownloadTask(org.jdesktop.application.Application application,
HttpDownloadClient client,
DownloadFile downloadFile,
ShareDownloadService service)
init
protected void init()
doInBackground
protected Void doInBackground()
throws Exception
- Specified by:
doInBackground
in class org.jdesktop.swingworker.SwingWorker<Void,Long>
- Throws:
Exception
initDownloadThread
protected void initDownloadThread()
getFileOutputStream
protected OutputStream getFileOutputStream(File f,
long fileSize)
throws NotEnoughSpaceException,
IOException
- Throws:
NotEnoughSpaceException
IOException
initBackground
protected void initBackground()
isTerminated
public boolean isTerminated()
- Description copied from interface:
HttpFileDownloadTask
- Checks whether current downloading process has been stopped
- Specified by:
isTerminated
in interface HttpFileDownloadTask
- Returns:
- true if downloading of the file was interrupted
saveToFile
public void saveToFile(InputStream inputStream)
throws Exception
- Description copied from interface:
HttpFileDownloadTask
- Method that handles direct saving file onto physical disc.
file download state is set to COMPLETED automatically
- Specified by:
saveToFile
in interface HttpFileDownloadTask
- Parameters:
inputStream
- - Http response stream, which contains data to be saved on the disk - should not be null
- Throws:
Exception
- Error during writing or if inputStream is null
useTemporaryFiles
protected boolean useTemporaryFiles()
cancelled
protected void cancelled()
- Overrides:
cancelled
in class org.jdesktop.application.Task<Void,Long>
setSpeed
protected void setSpeed(long speedInBytes)
setSleep
protected void setSleep(int sleep)
setDownloaded
protected void setDownloaded(long counter)
setAverageSpeed
protected void setAverageSpeed(float avgSpeed)
failed
protected void failed(Throwable cause)
- Overrides:
failed
in class CoreTask<Void,Long>
updateFileState
protected void updateFileState(Throwable cause,
boolean connectError)
error
protected void error(Throwable cause)
setFileErrorMessage
protected void setFileErrorMessage(Throwable cause)
interrupted
protected void interrupted(InterruptedException e)
- Overrides:
interrupted
in class org.jdesktop.application.Task<Void,Long>
succeeded
protected void succeeded(Void result)
- Overrides:
succeeded
in class org.jdesktop.application.Task<Void,Long>
checkExists
protected int checkExists()
throws InvocationTargetException,
InterruptedException
- Throws:
InvocationTargetException
InterruptedException
sleep
public void sleep(int seconds)
throws InterruptedException
- Description copied from interface:
HttpFileDownloadTask
- Sets file download state to WAITING.
Stops download thread for given time.
- Specified by:
sleep
in interface HttpFileDownloadTask
- Parameters:
seconds
- time to sleep
- Throws:
InterruptedException
- if the thread was interrupted during sleeping
getDownloadFile
public HttpFile getDownloadFile()
- Description copied from interface:
HttpFileDownloadTask
- Returns file that is given to be downloaded
- Specified by:
getDownloadFile
in interface HttpFileDownloadTask
- Returns:
- file for downloading
getClient
public HttpDownloadClient getClient()
- Description copied from interface:
HttpFileDownloadTask
- Client associated with current file - its HTTP connections are used to grab a file
- Specified by:
getClient
in interface HttpFileDownloadTask
- Returns:
- actual instance of HttpDownloadClient
getServiceError
public DownloadTaskError getServiceError()
getYouHaveToSleepSecondsTime
public int getYouHaveToSleepSecondsTime()
setDownloadFile
protected void setDownloadFile(DownloadFile downloadFile)