Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Get

extends Task
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, .OutputStream, .PrintStream, java.net.HttpURLConnection, .URL, .URLConnection, java.nio.file.Files, java.util.Date, .LinkedHashMap, .Map, java.util.zip.GZIPInputStream, org.apache.tools.ant.BuildException, .MagicNames, .Main, .Project, .Task, org.apache.tools.ant.taskdefs.email.Header, org.apache.tools.ant.types.Mapper, .Resource, .ResourceCollection, org.apache.tools.ant.types.resources.Resources, .URLProvider, .URLResource, org.apache.tools.ant.util.FileNameMapper, .FileUtils, .StringUtils

Gets a particular file from a URL source. Options include verbose reporting, timestamp based fetches and controlling actions on failures. NB: access through a firewall only works if the whole Java runtime is correctly configured.
Since
Ant 1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
Get.Base64Converter

Provide this for Backward Compatibility.

public static interface
Get.DownloadProgress

Interface implemented for reporting progress of downloading.

private class
public static class
Get.NullProgress

do nothing with progress info

public static class
Get.VerboseProgress

verbose progress system prints to some output stream

Field Summary

Modifier and TypeField and Description
private boolean
private static final int
private static final String
private File
private static final int
private static final FileUtils
private static final String
private Map<String, String>
private static final String
private static final int
private static final String
private boolean
private boolean
private Mapper
private long
private static final int
private int
private String
private boolean
private static final int
private boolean
private final Resources
private boolean
private String
private String
private boolean
private boolean
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public
Get()

Method Summary

Modifier and TypeMethod and Description
public void
add(final ResourceCollection
ResourceCollection
rc
)

Adds URLs to get.

public void
add(final FileNameMapper
the mapper to add.
fileNameMapper
)

Add a nested filenamemapper.

public void
addConfiguredHeader(Header
to be added
header
)

Add a nested header

private void
checkAttributes()

Check the attributes.

public Mapper

Returns:

a mapper to be configured.
createMapper
()

Define the mapper to map source to destination files.

public boolean

Returns:

true for a successful download, false otherwise. The return value is only relevant when ignoreErrors is true, as when false all failures raise BuildExceptions.
doGet
(final int
level to log at, see Project#log(String, int)
logLevel
,
final Get.DownloadProgress
progress callback; null for no-callbacks
progress
)

Deprecated only gets the first configured resource
make a get request, with the supplied progress and logging info.
public boolean

Returns:

true for a successful download, false otherwise. The return value is only relevant when ignoreErrors is true, as when false all failures raise BuildExceptions.
doGet
(final URL
the URL to get
source
,
final File
the target file
dest
,
final int
level to log at, see Project#log(String, int)
logLevel
,
Get.DownloadProgress
progress callback; null for no-callbacks
progress
)

make a get request, with the supplied progress and logging info.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Does the work.
public static boolean
isMoved(final int responseCode)

Does the response code represent a redirection?

public void
log(final String
The message to be logged. Should not be null.
msg
,
final int
The message priority at which this message is to be logged.
msgLevel
)

Overrides org.apache.tools.ant.Task.log.

Logs a message with the given priority.
public void
setAuthenticateOnRedirect(final boolean
"true" to enable sending the credentials on redirect; "false" otherwise
v
)

If true, credentials are set when following a redirect to a new location.

public void
setDest(final File
Path to file.
dest
)

Where to copy the source file.

public void
setHttpUseCaches(final boolean
boolean
httpUseCache
)

HTTP connections only - control caching on the HttpUrlConnection: httpConnection.setUseCaches(); if false, do not allow caching on the HttpUrlConnection.

public void
setIgnoreErrors(final boolean
if "true" then don't report download errors up to ant
v
)

If true, log errors but do not treat as fatal.

public void
setMaxTime(final long
long
maxTime
)

The time in seconds the download is allowed to take before being terminated.

public void
setPassword(final String
password for authentication
p
)

password for the basic authentication.

public void
setQuiet(final boolean
if "true" then be quiet
v
)

If true, set default log level to Project.MSG_ERR.

public void
setRetries(final int
number of attempts to make
r
)

The number of attempts to make for opening the URI, defaults to 3.

public void
setSkipExisting(final boolean
"true" to skip existing destination files
s
)

Skip files that already exist locally.

public void
setSrc(final URL
URL for the file.
u
)

Set an URL to get.

public void
setTryGzipEncoding(boolean
boolean
b
)

Whether to transparently try to reduce bandwidth by telling the server ant would support gzip encoding.

public void
setUserAgent(final String
String
userAgent
)

HTTP connections only - set the user-agent to be used when communicating with remote server.

public void
setUsername(final String
username for authentication
u
)

Username for basic auth.

public void
setUseTimestamp(final boolean
"true" to enable file time fetching
v
)

If true, conditionally download a file based on the timestamp of the local copy.

public void
setVerbose(final boolean
if "true" then be verbose
v
)

If true, show verbose progress information.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidlogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

authenticateOnRedirectback to summary
private boolean authenticateOnRedirect
BIG_BUFFER_SIZEback to summary
private static final int BIG_BUFFER_SIZE
DEFAULT_AGENT_PREFIXback to summary
private static final String DEFAULT_AGENT_PREFIX
destinationback to summary
private File destination
DOTS_PER_LINEback to summary
private static final int DOTS_PER_LINE
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
GZIP_CONTENT_ENCODINGback to summary
private static final String GZIP_CONTENT_ENCODING
headersback to summary
private Map<String, String> headers
HTTPback to summary
private static final String HTTP
HTTP_MOVED_TEMPback to summary
private static final int HTTP_MOVED_TEMP
HTTPSback to summary
private static final String HTTPS
httpUseCachesback to summary
private boolean httpUseCaches
ignoreErrorsback to summary
private boolean ignoreErrors
mapperElementback to summary
private Mapper mapperElement
maxTimeback to summary
private long maxTime
NUMBER_RETRIESback to summary
private static final int NUMBER_RETRIES
numberRetriesback to summary
private int numberRetries
pwordback to summary
private String pword
quietback to summary
private boolean quiet
REDIRECT_LIMITback to summary
private static final int REDIRECT_LIMIT
skipExistingback to summary
private boolean skipExisting
sourcesback to summary
private final Resources sources
tryGzipEncodingback to summary
private boolean tryGzipEncoding
unameback to summary
private String uname
userAgentback to summary
private String userAgent
useTimestampback to summary
private boolean useTimestamp
verboseback to summary
private boolean verbose

Constructor Detail

Getback to summary
public Get()

Method Detail

addback to summary
public void add(final ResourceCollection rc)

Adds URLs to get.

Parameters
rc:ResourceCollection

ResourceCollection

Since
Ant 1.8.0
addback to summary
public void add(final FileNameMapper fileNameMapper)

Add a nested filenamemapper.

Parameters
fileNameMapper:FileNameMapper

the mapper to add.

Since
Ant 1.8.0
addConfiguredHeaderback to summary
public void addConfiguredHeader(Header header)

Add a nested header

Parameters
header:Header

to be added

checkAttributesback to summary
private void checkAttributes()

Check the attributes.

createMapperback to summary
public Mapper createMapper() throws BuildException

Define the mapper to map source to destination files.

Returns:Mapper

a mapper to be configured.

Exceptions
BuildException:
if more than one mapper is defined.
Since
Ant 1.8.0
doGetback to summary
public boolean doGet(final int logLevel, final Get.DownloadProgress progress) throws IOException

Deprecated

only gets the first configured resource

make a get request, with the supplied progress and logging info. All the other config parameters are set at the task level, source, dest, ignoreErrors, etc.

Parameters
logLevel:int

level to log at, see Project#log(String, int)

progress:Get.DownloadProgress

progress callback; null for no-callbacks

Returns:boolean

true for a successful download, false otherwise. The return value is only relevant when ignoreErrors is true, as when false all failures raise BuildExceptions.

Annotations
@Deprecated
Exceptions
IOException:
for network trouble
BuildException:
for argument errors, or other trouble when ignoreErrors is false.
doGetback to summary
public boolean doGet(final URL source, final File dest, final int logLevel, Get.DownloadProgress progress) throws IOException

make a get request, with the supplied progress and logging info. All the other config parameters like ignoreErrors are set at the task level.

Parameters
source:URL

the URL to get

dest:File

the target file

logLevel:int

level to log at, see Project#log(String, int)

progress:Get.DownloadProgress

progress callback; null for no-callbacks

Returns:boolean

true for a successful download, false otherwise. The return value is only relevant when ignoreErrors is true, as when false all failures raise BuildExceptions.

Exceptions
IOException:
for network trouble
BuildException:
for argument errors, or other trouble when ignoreErrors is false.
Since
Ant 1.8.0
executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Does the work.

Annotations
@Override
Exceptions
BuildException:
Thrown in unrecoverable error.
isMovedback to summary
public static boolean isMoved(final int responseCode)

Does the response code represent a redirection?

Since
1.10.10
logback to summary
public void log(final String msg, final int msgLevel)

Overrides org.apache.tools.ant.Task.log.

Doc from org.apache.tools.ant.Task.log.

Logs a message with the given priority. This delegates the actual logging to the project.

Parameters
msg:String

The message to be logged. Should not be null.

msgLevel:int

The message priority at which this message is to be logged.

Annotations
@Override
setAuthenticateOnRedirectback to summary
public void setAuthenticateOnRedirect(final boolean v)

If true, credentials are set when following a redirect to a new location.

Parameters
v:boolean

"true" to enable sending the credentials on redirect; "false" otherwise

Since
Ant 1.10.13
setDestback to summary
public void setDest(final File dest)

Where to copy the source file.

Parameters
dest:File

Path to file.

setHttpUseCachesback to summary
public void setHttpUseCaches(final boolean httpUseCache)

HTTP connections only - control caching on the HttpUrlConnection: httpConnection.setUseCaches(); if false, do not allow caching on the HttpUrlConnection.

Defaults to true (allow caching, which is also the HttpUrlConnection default value.

Parameters
httpUseCache:boolean

boolean

Since
Ant 1.8.0
setIgnoreErrorsback to summary
public void setIgnoreErrors(final boolean v)

If true, log errors but do not treat as fatal.

Parameters
v:boolean

if "true" then don't report download errors up to ant

setMaxTimeback to summary
public void setMaxTime(final long maxTime)

The time in seconds the download is allowed to take before being terminated.

Parameters
maxTime:long

long

Since
Ant 1.8.0
setPasswordback to summary
public void setPassword(final String p)

password for the basic authentication.

Parameters
p:String

password for authentication

setQuietback to summary
public void setQuiet(final boolean v)

If true, set default log level to Project.MSG_ERR.

Parameters
v:boolean

if "true" then be quiet

Since
Ant 1.9.4
setRetriesback to summary
public void setRetries(final int r)

The number of attempts to make for opening the URI, defaults to 3.

The name of the method is misleading as a value of 1 means "don't retry on error" and a value of 0 meant don't even try to reach the URI at all.

Parameters
r:int

number of attempts to make

Since
Ant 1.8.0
setSkipExistingback to summary
public void setSkipExisting(final boolean s)

Skip files that already exist locally.

Parameters
s:boolean

"true" to skip existing destination files

Since
Ant 1.8.0
setSrcback to summary
public void setSrc(final URL u)

Set an URL to get.

Parameters
u:URL

URL for the file.

setTryGzipEncodingback to summary
public void setTryGzipEncoding(boolean b)

Whether to transparently try to reduce bandwidth by telling the server ant would support gzip encoding.

Setting this to true also means Ant will uncompress .tar.gz and similar files automatically.

Parameters
b:boolean

boolean

Since
Ant 1.9.5
setUserAgentback to summary
public void setUserAgent(final String userAgent)

HTTP connections only - set the user-agent to be used when communicating with remote server. if null, then the value is considered unset and the behaviour falls back to the default of the http API.

Parameters
userAgent:String

String

Since
Ant 1.9.3
setUsernameback to summary
public void setUsername(final String u)

Username for basic auth.

Parameters
u:String

username for authentication

setUseTimestampback to summary
public void setUseTimestamp(final boolean v)

If true, conditionally download a file based on the timestamp of the local copy.

In this situation, the if-modified-since header is set so that the file is only fetched if it is newer than the local file (or there is no local file) This flag is only valid on HTTP connections, it is ignored in other cases. When the flag is set, the local copy of the downloaded file will also have its timestamp set to the remote file time.

Note that remote files of date 1/1/1970 (GMT) are treated as 'no timestamp', and web servers often serve files with a timestamp in the future by replacing their timestamp with that of the current time. Also, inter-computer clock differences can cause no end of grief.

Parameters
v:boolean

"true" to enable file time fetching

setVerboseback to summary
public void setVerbose(final boolean v)

If true, show verbose progress information.

Parameters
v:boolean

if "true" then be verbose

org.apache.tools.ant.taskdefs back to summary

protected Class Get.Base64Converter

extends Base64Converter
Class Inheritance

Provide this for Backward Compatibility.

Field Summary

Inherited from org.apache.tools.ant.util.Base64Converter:
alphabet

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Inherited from org.apache.tools.ant.util.Base64Converter:
encodeencode

Constructor Detail

Base64Converterback to summary
protected Base64Converter()
org.apache.tools.ant.taskdefs back to summary

public Interface Get.DownloadProgress

Known Direct Implementers
org.apache.tools.ant.taskdefs.Get.NullProgress, org.apache.tools.ant.taskdefs.Get.VerboseProgress

Interface implemented for reporting progress of downloading.

Method Summary

Modifier and TypeMethod and Description
public void
beginDownload()

begin a download

public void
endDownload()

end a download

public void
onTick()

tick handler

Method Detail

beginDownloadback to summary
public void beginDownload()

begin a download

endDownloadback to summary
public void endDownload()

end a download

onTickback to summary
public void onTick()

tick handler

org.apache.tools.ant.taskdefs back to summary

private Class Get.GetThread

extends Thread
Class Inheritance

Field Summary

Modifier and TypeField and Description
private URLConnection
private final File
private BuildException
private final boolean
private IOException
private InputStream
private final int
private OutputStream
private final Get.DownloadProgress
private int
private final URL
private boolean
private final long
private String
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
pack-priv
GetThread(final URL source, final File dest, final boolean h, final long t, final Get.DownloadProgress p, final int l, final String userAgent)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
closeStreams()

Closes streams, interrupts the download, may delete the output file.

private boolean
private boolean
get()

private URLConnection
openConnection(final URL aSource, final String uname, final String pword)

private boolean
redirectionAllowed(final URL aSource, final URL aDest)

public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.
private void
pack-priv boolean
wasSuccessful()

Has the download completed successfully?

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitresumesetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopsuspendthreadIdtoStringyield

Field Detail

connectionback to summary
private URLConnection connection
destback to summary
private final File dest
exceptionback to summary
private BuildException exception
hasTimestampback to summary
private final boolean hasTimestamp
ioexceptionback to summary
private IOException ioexception
isback to summary
private InputStream is
logLevelback to summary
private final int logLevel
osback to summary
private OutputStream os
progressback to summary
private final Get.DownloadProgress progress
redirectionsback to summary
private int redirections
sourceback to summary
private final URL source
successback to summary
private boolean success
timestampback to summary
private final long timestamp
userAgentback to summary
private String userAgent

Constructor Detail

GetThreadback to summary
pack-priv GetThread(final URL source, final File dest, final boolean h, final long t, final Get.DownloadProgress p, final int l, final String userAgent)

Method Detail

closeStreamsback to summary
pack-priv void closeStreams()

Closes streams, interrupts the download, may delete the output file.

downloadFileback to summary
private boolean downloadFile() throws IOException
getback to summary
private boolean get() throws IOException, BuildException
openConnectionback to summary
private URLConnection openConnection(final URL aSource, final String uname, final String pword) throws IOException
redirectionAllowedback to summary
private boolean redirectionAllowed(final URL aSource, final URL aDest)
runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override
updateTimeStampback to summary
private void updateTimeStamp()
wasSuccessfulback to summary
pack-priv boolean wasSuccessful() throws IOException, BuildException

Has the download completed successfully?

Re-throws any exception caught during execution.

org.apache.tools.ant.taskdefs back to summary

public Class Get.NullProgress

extends Object
implements DownloadProgress
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.Get.DownloadProgress

do nothing with progress info

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NullProgressback to summary
public NullProgress()

Method Detail

beginDownloadback to summary
public void beginDownload()

Implements org.apache.tools.ant.taskdefs.Get.DownloadProgress.beginDownload.

begin a download

Annotations
@Override
endDownloadback to summary
public void endDownload()

Implements org.apache.tools.ant.taskdefs.Get.DownloadProgress.endDownload.

end a download

Annotations
@Override
onTickback to summary
public void onTick()

Implements org.apache.tools.ant.taskdefs.Get.DownloadProgress.onTick.

tick handler

Annotations
@Override
org.apache.tools.ant.taskdefs back to summary

public Class Get.VerboseProgress

extends Object
implements DownloadProgress
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.Get.DownloadProgress

verbose progress system prints to some output stream

Field Summary

Modifier and TypeField and Description
private int
pack-priv PrintStream

Constructor Summary

AccessConstructor and Description
public
VerboseProgress(final PrintStream
the output stream.
out
)

Construct a verbose progress reporter.

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dotsback to summary
private int dots
outback to summary
pack-priv PrintStream out

Constructor Detail

VerboseProgressback to summary
public VerboseProgress(final PrintStream out)

Construct a verbose progress reporter.

Parameters
out:PrintStream

the output stream.

Method Detail

beginDownloadback to summary
public void beginDownload()

Implements org.apache.tools.ant.taskdefs.Get.DownloadProgress.beginDownload.

begin a download

Annotations
@Override
endDownloadback to summary
public void endDownload()

Implements org.apache.tools.ant.taskdefs.Get.DownloadProgress.endDownload.

end a download

Annotations
@Override
onTickback to summary
public void onTick()

Implements org.apache.tools.ant.taskdefs.Get.DownloadProgress.onTick.

tick handler

Annotations
@Override