org.apache.tools.ant.types.resources

Class URLResource

Implemented Interfaces:
Cloneable, Comparable, ResourceCollection

public class URLResource
extends Resource

Exposes a URL as a Resource.
Since:
Ant 1.7

Field Summary

Fields inherited from class org.apache.tools.ant.types.Resource

MAGIC, UNKNOWN_DATETIME, UNKNOWN_SIZE

Fields inherited from class org.apache.tools.ant.types.DataType

checked, ref

Fields inherited from class org.apache.tools.ant.ProjectComponent

description, location, project

Constructor Summary

URLResource()
Default constructor.
URLResource(File f)
Convenience constructor.
URLResource(String u)
String constructor for Ant attribute introspection.
URLResource(URL u)
Convenience constructor.

Method Summary

protected void
connect()
Ensure that we have a connection.
boolean
equals(Object another)
Test whether an Object equals this URLResource.
InputStream
getInputStream()
Get an InputStream for the Resource.
long
getLastModified()
Tells the modification time in milliseconds since 01.01.1970 .
String
getName()
Get the name of this URLResource (its file component minus the leading separator).
OutputStream
getOutputStream()
Get an OutputStream for the Resource.
long
getSize()
Get the size of this Resource.
URL
getURL()
Get the URL used by this URLResource.
int
hashCode()
Get the hash code for this Resource.
boolean
isDirectory()
Tells if the resource is a directory.
boolean
isExists()
Find out whether the URL exists .
void
setFile(File f)
Set the URL from a File.
void
setRefid(Reference r)
Overrides the super version.
void
setURL(URL u)
Set the URL for this URLResource.
String
toString()
Return this URLResource formatted as a String.

Methods inherited from class org.apache.tools.ant.types.Resource

clone, compareTo, equals, getInputStream, getLastModified, getMagicNumber, getName, getOutputStream, getSize, hashCode, isDirectory, isExists, isFilesystemOnly, iterator, setDirectory, setExists, setLastModified, setName, setRefid, setSize, size, toLongString, toString

Methods inherited from class org.apache.tools.ant.types.DataType

checkAttributesAllowed, checkChildrenAllowed, circularReference, clone, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, setChecked, setRefid, toString, tooManyAttributes

Methods inherited from class org.apache.tools.ant.ProjectComponent

clone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject

Constructor Details

URLResource

public URLResource()
Default constructor.

URLResource

public URLResource(File f)
Convenience constructor.
Parameters:
f - the File to set as a URL.

URLResource

public URLResource(String u)
String constructor for Ant attribute introspection.
Parameters:
u - String representation of this URL.

URLResource

public URLResource(URL u)
Convenience constructor.
Parameters:
u - the URL to expose.

Method Details

connect

protected void connect()
            throws IOException
Ensure that we have a connection.

equals

public boolean equals(Object another)
Test whether an Object equals this URLResource.
Overrides:
equals in interface Resource
Parameters:
another - the other Object to compare.
Returns:
true if the specified Object is equal to this Resource.

getInputStream

public InputStream getInputStream()
            throws IOException
Get an InputStream for the Resource.
Overrides:
getInputStream in interface Resource
Returns:
an InputStream containing this Resource's content.

getLastModified

public long getLastModified()
Tells the modification time in milliseconds since 01.01.1970 .
Overrides:
getLastModified in interface Resource
Returns:
0 if the resource does not exist to mirror the behavior of File.

getName

public String getName()
Get the name of this URLResource (its file component minus the leading separator).
Overrides:
getName in interface Resource
Returns:
the name of this resource.

getOutputStream

public OutputStream getOutputStream()
            throws IOException
Get an OutputStream for the Resource.
Overrides:
getOutputStream in interface Resource
Returns:
an OutputStream to which content can be written.

getSize

public long getSize()
Get the size of this Resource.
Overrides:
getSize in interface Resource
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.

getURL

public URL getURL()
Get the URL used by this URLResource.
Returns:
a URL object.

hashCode

public int hashCode()
Get the hash code for this Resource.
Overrides:
hashCode in interface Resource
Returns:
hash code as int.

isDirectory

public boolean isDirectory()
Tells if the resource is a directory.
Overrides:
isDirectory in interface Resource
Returns:
boolean whether the resource is a directory.

isExists

public boolean isExists()
Find out whether the URL exists .
Overrides:
isExists in interface Resource
Returns:
true if this resource exists.

setFile

public void setFile(File f)
Set the URL from a File.
Parameters:
f - the File to set as a URL.

setRefid

public void setRefid(Reference r)
Overrides the super version.
Overrides:
setRefid in interface Resource
Parameters:
r - the Reference to set.

setURL

public void setURL(URL u)
Set the URL for this URLResource.
Parameters:
u - the URL to expose.

toString

public String toString()
Return this URLResource formatted as a String.
Overrides:
toString in interface Resource
Returns:
a String representation of this URLResource.