Top Description Inners Fields Constructors Methods
org.apache.tools.ant.types.resources

public Class URLResource

extends Resource
implements URLProvider
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.types.resources.URLProvider
Imports
java.io.File, .IOException, .InputStream, .OutputStream, java.net.HttpURLConnection, .MalformedURLException, .URL, .URLConnection, org.apache.tools.ant.BuildException, .Project, org.apache.tools.ant.types.Reference, .Resource, org.apache.tools.ant.util.FileUtils

Exposes a URL as a Resource.
Since
Ant 1.7

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface

Field Summary

Modifier and TypeField and Description
private URL
private URLConnection
private static final FileUtils
private static final int
private String
private URL
Inherited from org.apache.tools.ant.types.Resource:
MAGICUNKNOWN_DATETIMEUNKNOWN_SIZE

Constructor Summary

AccessConstructor and Description
public
URLResource()

Default constructor.

public
URLResource(URL
the URL to expose.
u
)

Convenience constructor.

public
URLResource(URLProvider
holds the URL to expose.
u
)

Convenience constructor.

public
URLResource(File
the File to set as a URL.
f
)

Convenience constructor.

public
URLResource(String
String representation of this URL.
u
)

String constructor for Ant attribute introspection.

Method Summary

Modifier and TypeMethod and Description
private synchronized void
close()

Closes the URL connection if: - it is opened (i.e. the field conn is not null) - this type of URLConnection supports some sort of close mechanism This method ensures the field conn will be null after the call.

protected void
connect()

Ensure that we have a connection.

protected synchronized void
connect(int
severity to use when logging connection errors. Should be one of the MSG_ constants in Project.
logLevel
)

Ensure that we have a connection.

public synchronized boolean

Returns:

true if the specified Object is equal to this Resource.
equals
(Object
the other Object to compare.
another
)

Overrides org.apache.tools.ant.types.Resource.equals.

Test whether an Object equals this URLResource.
public synchronized InputStream

Returns:

an InputStream containing this Resource's content.
getInputStream
()

Overrides org.apache.tools.ant.types.Resource.getInputStream.

Get an InputStream for the Resource.
public synchronized long

Returns:

0 if the resource does not exist to mirror the behavior of File.
getLastModified
()

Overrides org.apache.tools.ant.types.Resource.getLastModified.

Tells the modification time in milliseconds since 01.01.1970 .
public synchronized String

Returns:

the name of this resource.
getName
()

Overrides org.apache.tools.ant.types.Resource.getName.

Get the name of this URLResource (its file component minus the leading separator).
public synchronized OutputStream

Returns:

an OutputStream to which content can be written.
getOutputStream
()

Overrides org.apache.tools.ant.types.Resource.getOutputStream.

Get an OutputStream for the Resource.
protected URLResource
getRef()

Overrides org.apache.tools.ant.types.Resource.getRef.

Perform the check for circular references and return the referenced Resource.
public synchronized long

Returns:

the size, as a long, 0 if the Resource does not exist (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.
getSize
()

Overrides org.apache.tools.ant.types.Resource.getSize.

Get the size of this Resource.
public synchronized URL

Returns:

a URL object.
getURL
()

Implements org.apache.tools.ant.types.resources.URLProvider.getURL.

Get the URL used by this URLResource.
public synchronized int

Returns:

hash code as int.
hashCode
()

Overrides org.apache.tools.ant.types.Resource.hashCode.

Get the hash code for this Resource.
public synchronized boolean

Returns:

boolean whether the resource is a directory.
isDirectory
()

Overrides org.apache.tools.ant.types.Resource.isDirectory.

Tells if the resource is a directory.
public synchronized boolean

Returns:

true if this resource exists.
isExists
()

Overrides org.apache.tools.ant.types.Resource.isExists.

Find out whether the URL exists .
private synchronized boolean

Returns:

true if this resource exists.
isExists
(boolean
true if the connection should be closed after the call, false if it should stay open.
closeConnection
)

Find out whether the URL exists, and close the connection opened to the URL if closeConnection is true.

private static URL
public synchronized void
setBaseURL(URL
URL
base
)

Base URL which combined with the relativePath attribute defines the URL.

public synchronized void
setFile(File
the File to set as a URL.
f
)

Set the URL from a File.

public synchronized void
setRefid(Reference
the Reference to set.
r
)

Overrides org.apache.tools.ant.types.Resource.setRefid.

Overrides the super version.
public synchronized void
setRelativePath(String
String
r
)

Relative path which combined with the baseURL attribute defines the URL.

public synchronized void
setURL(URL
the URL to expose.
u
)

Set the URL for this URLResource.

public synchronized String

Returns:

a String representation of this URLResource.
toString
()

Overrides org.apache.tools.ant.types.Resource.toString.

Return this URLResource formatted as a String.
private long
Inherited from org.apache.tools.ant.types.Resource:
asasOptionalclonecompareTogetMagicNumberisFilesystemOnlyiteratorsetDirectorysetExistssetLastModifiedsetNamesetSizesizetoLongString

Field Detail

baseURLback to summary
private URL baseURL
connback to summary
private URLConnection conn
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
NULL_URLback to summary
private static final int NULL_URL
relPathback to summary
private String relPath
urlback to summary
private URL url

Constructor Detail

URLResourceback to summary
public URLResource()

Default constructor.

URLResourceback to summary
public URLResource(URL u)

Convenience constructor.

Parameters
u:URL

the URL to expose.

URLResourceback to summary
public URLResource(URLProvider u)

Convenience constructor.

Parameters
u:URLProvider

holds the URL to expose.

URLResourceback to summary
public URLResource(File f)

Convenience constructor.

Parameters
f:File

the File to set as a URL.

URLResourceback to summary
public URLResource(String u)

String constructor for Ant attribute introspection.

Parameters
u:String

String representation of this URL.

See Also
org.apache.tools.ant.IntrospectionHelper

Method Detail

closeback to summary
private synchronized void close()

Closes the URL connection if: - it is opened (i.e. the field conn is not null) - this type of URLConnection supports some sort of close mechanism This method ensures the field conn will be null after the call.

connectback to summary
protected void connect() throws IOException

Ensure that we have a connection.

Exceptions
IOException:
if the connection cannot be established.
connectback to summary
protected synchronized void connect(int logLevel) throws IOException

Ensure that we have a connection.

Parameters
logLevel:int

severity to use when logging connection errors. Should be one of the MSG_ constants in Project.

Exceptions
IOException:
if the connection cannot be established.
Since
Ant 1.8.2
equalsback to summary
public synchronized boolean equals(Object another)

Overrides org.apache.tools.ant.types.Resource.equals.

Test whether an Object equals this URLResource.

Parameters
another:Object

the other Object to compare.

Returns:boolean

true if the specified Object is equal to this Resource.

getInputStreamback to summary
public synchronized InputStream getInputStream() throws IOException

Overrides org.apache.tools.ant.types.Resource.getInputStream.

Get an InputStream for the Resource.

Returns:InputStream

an InputStream containing this Resource's content.

Exceptions
IOException:
if unable to provide the content of this Resource as a stream.
UnsupportedOperationException:
if InputStreams are not supported for this Resource type.
getLastModifiedback to summary
public synchronized long getLastModified()

Overrides org.apache.tools.ant.types.Resource.getLastModified.

Tells the modification time in milliseconds since 01.01.1970 .

Returns:long

0 if the resource does not exist to mirror the behavior of File.

getNameback to summary
public synchronized String getName()

Overrides org.apache.tools.ant.types.Resource.getName.

Get the name of this URLResource (its file component minus the leading separator).

Returns:String

the name of this resource.

getOutputStreamback to summary
public synchronized OutputStream getOutputStream() throws IOException

Overrides org.apache.tools.ant.types.Resource.getOutputStream.

Get an OutputStream for the Resource.

Returns:OutputStream

an OutputStream to which content can be written.

Exceptions
IOException:
  • if unable to provide the content of this Resource as a stream.
  • if the URL cannot be opened.
UnsupportedOperationException:
if OutputStreams are not supported for this Resource type.
getRefback to summary
protected URLResource getRef()

Overrides org.apache.tools.ant.types.Resource.getRef.

Doc from org.apache.tools.ant.types.Resource.getRef.

Perform the check for circular references and return the referenced Resource.

Returns:URLResource

Resource.

Annotations
@Override
getSizeback to summary
public synchronized long getSize()

Overrides org.apache.tools.ant.types.Resource.getSize.

Get the size of this Resource.

Returns:long

the size, as a long, 0 if the Resource does not exist (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.

getURLback to summary
public synchronized URL getURL()

Implements org.apache.tools.ant.types.resources.URLProvider.getURL.

Get the URL used by this URLResource.

Returns:URL

a URL object.

hashCodeback to summary
public synchronized int hashCode()

Overrides org.apache.tools.ant.types.Resource.hashCode.

Get the hash code for this Resource.

Returns:int

hash code as int.

isDirectoryback to summary
public synchronized boolean isDirectory()

Overrides org.apache.tools.ant.types.Resource.isDirectory.

Tells if the resource is a directory.

Returns:boolean

boolean whether the resource is a directory.

isExistsback to summary
public synchronized boolean isExists()

Overrides org.apache.tools.ant.types.Resource.isExists.

Find out whether the URL exists .

Returns:boolean

true if this resource exists.

isExistsback to summary
private synchronized boolean isExists(boolean closeConnection)

Find out whether the URL exists, and close the connection opened to the URL if closeConnection is true. Note that this method does ensure that if: - the resource exists (if it returns true) - and if the current object is not a reference (isReference() returns false) - and if it was called with closeConnection to false, then the connection to the URL (stored in the conn private field) will be opened, and require to be closed by the caller.

Parameters
closeConnection:boolean

true if the connection should be closed after the call, false if it should stay open.

Returns:boolean

true if this resource exists.

newURLback to summary
private static URL newURL(String u)
setBaseURLback to summary
public synchronized void setBaseURL(URL base)

Base URL which combined with the relativePath attribute defines the URL.

Parameters
base:URL

URL

Since
Ant 1.8.0
setFileback to summary
public synchronized void setFile(File f)

Set the URL from a File.

Parameters
f:File

the File to set as a URL.

setRefidback to summary
public synchronized void setRefid(Reference r)

Overrides org.apache.tools.ant.types.Resource.setRefid.

Overrides the super version.

Parameters
r:Reference

the Reference to set.

setRelativePathback to summary
public synchronized void setRelativePath(String r)

Relative path which combined with the baseURL attribute defines the URL.

Parameters
r:String

String

Since
Ant 1.8.0
setURLback to summary
public synchronized void setURL(URL u)

Set the URL for this URLResource.

Parameters
u:URL

the URL to expose.

toStringback to summary
public synchronized String toString()

Overrides org.apache.tools.ant.types.Resource.toString.

Return this URLResource formatted as a String.

Returns:String

a String representation of this URLResource.

withConnectionback to summary
private long withConnection(URLResource.ConnectionUser u, long defaultValue)
org.apache.tools.ant.types.resources back to summary

private Interface URLResource.ConnectionUser


Method Summary

Modifier and TypeMethod and Description
public long

Method Detail

useConnectionback to summary
public long useConnection(URLConnection c)