public class DownloadTask extends DefaultTask implements DownloadSpec
Notable differences: Wayyy simpler implementation. Lazy evaluation of file and URL inputs. Single file downloads. External validation of file for up-to-date checking. UserAgent spoofing. (Thanks mojang!) Ability to set the ProgressLogger to use.
This is split into an Action, Spec and Task.
The Spec DownloadSpec, Provides the specification for how things work.
The Action DownloadAction, What actually handles downloading
implements DownloadSpec, Useful for other tasks that need to download
something but not necessarily create an entire task to do said download.
The Task DownloadTask for gradle, Task wrapper for DownloadAction,
implements DownloadSpec and hosts the Action as a task.
Created by covers1624 on 8/02/19.
| Constructor and Description |
|---|
DownloadTask() |
| Modifier and Type | Method and Description |
|---|---|
void |
doTask() |
void |
fileUpToDateWhen(<any> spec)
Spec to validate the already existing file this DownloadSpec will download.
|
java.nio.file.Path |
getDest()
Gets the destination file to download to.
|
java.nio.file.Path |
getETagFile()
The file to store the ETag in.
|
DownloadListener |
getListener()
Gets the currently attached
DownloadListener. |
boolean |
getOnlyIfModified() |
java.net.URL |
getSrc()
Gets the source URL for the file that will be downloaded.
|
DownloadAction.UseETag |
getUseETag() |
java.lang.String |
getUserAgent()
Gets the User-Agent header this DownloadSpec will use for requests.
|
boolean |
isQuiet()
If this DownloadSpec is being quiet.
|
boolean |
isUpToDate()
To be used after the DownloadSpec has been executed,
will return weather the DownloadSpec was up-to-date and
no work was performed.
|
void |
setDest(java.io.File dest)
Sets the destination to store the downloaded file.
|
void |
setDest(java.nio.file.Path dest)
Sets the destination to store the downloaded file.
|
void |
setETagFile(java.io.File eTagFile)
Sets the file to store the ETag in.
|
void |
setETagFile(java.nio.file.Path eTagFile)
Sets the file to store the ETag in.
|
void |
setListener(DownloadListener listener)
Forcibly set the DownloadListener to use for this DownloadSpec.
|
void |
setOnlyIfModified(boolean onlyIfModified)
Sets weather this DownloadSpec should obey onlyIfModified HTTP headers.
|
void |
setQuiet(boolean quiet)
Sets weather quiet is enabled or not.
|
void |
setSrc(java.lang.Object src)
Sets the source URL to download.
|
void |
setUseETag(java.lang.Object useETag)
Sets weather this DownloadSpec should use ETags for HTTP requests.
|
void |
setUserAgent(java.lang.String userAgent)
Sets the User-Agent HTTP header string to use for HTTP requests.
|
public void doTask()
throws java.io.IOException
java.io.IOExceptionpublic void fileUpToDateWhen(<any> spec)
DownloadSpecBasically, using this allows you to determine externally if the file is corrupt and force a re-download at execution time instead of pre maturely.
fileUpToDateWhen in interface DownloadSpecspec - The Spec.public java.net.URL getSrc()
DownloadSpecgetSrc in interface DownloadSpecpublic java.nio.file.Path getDest()
DownloadSpecgetDest in interface DownloadSpecpublic boolean getOnlyIfModified()
getOnlyIfModified in interface DownloadSpecpublic DownloadAction.UseETag getUseETag()
getUseETag in interface DownloadSpecpublic java.nio.file.Path getETagFile()
DownloadSpecgetETagFile in interface DownloadSpecpublic java.lang.String getUserAgent()
DownloadSpecgetUserAgent in interface DownloadSpecpublic boolean isQuiet()
DownloadSpecisQuiet in interface DownloadSpecpublic boolean isUpToDate()
DownloadSpecisUpToDate in interface DownloadSpecpublic DownloadListener getListener()
DownloadSpecDownloadListener.getListener in interface DownloadSpecpublic void setSrc(java.lang.Object src)
DownloadSpecsetSrc in interface DownloadSpecsrc - The source.public void setDest(java.nio.file.Path dest)
DownloadSpecsetDest in interface DownloadSpecdest - The destination.public void setDest(java.io.File dest)
DownloadSpecsetDest in interface DownloadSpecdest - The destination.public void setOnlyIfModified(boolean onlyIfModified)
DownloadSpecsetOnlyIfModified in interface DownloadSpeconlyIfModified - Weather to use onlyIfModified.public void setUseETag(java.lang.Object useETag)
DownloadSpecsetUseETag in interface DownloadSpecuseETag - Weather to use ETags.public void setETagFile(java.nio.file.Path eTagFile)
DownloadSpecsetETagFile in interface DownloadSpeceTagFile - The file to store the ETag in.public void setETagFile(java.io.File eTagFile)
DownloadSpecsetETagFile in interface DownloadSpeceTagFile - The file to store the ETag in.public void setUserAgent(java.lang.String userAgent)
DownloadSpecsetUserAgent in interface DownloadSpecuserAgent - The User-Agent string.public void setQuiet(boolean quiet)
DownloadSpecsetQuiet in interface DownloadSpecquiet - If quiet is enabled.public void setListener(DownloadListener listener)
DownloadSpecsetListener in interface DownloadSpeclistener - The DownloadListener.