org.apache.tools.ant.types.resources

Class URLResource

public class URLResource extends Resource

Exposes a URL as a Resource.

Since: Ant 1.7

Constructor Summary
URLResource()
Default constructor.
URLResource(URL u)
Convenience constructor.
URLResource(File f)
Convenience constructor.
URLResource(String u)
String constructor for Ant attribute introspection.
Method Summary
protected voidconnect()
Ensure that we have a connection.
booleanequals(Object another)
Test whether an Object equals this URLResource.
InputStreamgetInputStream()
Get an InputStream for the Resource.
longgetLastModified()
Tells the modification time in milliseconds since 01.01.1970 .
StringgetName()
Get the name of this URLResource (its file component minus the leading separator).
OutputStreamgetOutputStream()
Get an OutputStream for the Resource.
longgetSize()
Get the size of this Resource.
URLgetURL()
Get the URL used by this URLResource.
inthashCode()
Get the hash code for this Resource.
booleanisDirectory()
Tells if the resource is a directory.
booleanisExists()
Find out whether the URL exists .
voidsetFile(File f)
Set the URL from a File.
voidsetRefid(Reference r)
Overrides the super version.
voidsetURL(URL u)
Set the URL for this URLResource.
StringtoString()
Return this URLResource formatted as a String.

Constructor Detail

URLResource

public URLResource()
Default constructor.

URLResource

public URLResource(URL u)
Convenience constructor.

Parameters: u the URL to expose.

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.

See Also: IntrospectionHelper

Method Detail

connect

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

Throws: IOException if the connection cannot be established.

equals

public boolean equals(Object another)
Test whether an Object equals this URLResource.

Parameters: another the other Object to compare.

Returns: true if the specified Object is equal to this Resource.

getInputStream

public InputStream getInputStream()
Get an InputStream for the Resource.

Returns: an InputStream containing this Resource's content.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if InputStreams are not supported for this Resource type.

getLastModified

public long getLastModified()
Tells the modification time in milliseconds since 01.01.1970 .

Returns: 0 if the resource does not exist to mirror the behavior of {@link java.io.File File}.

getName

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

Returns: the name of this resource.

getOutputStream

public OutputStream getOutputStream()
Get an OutputStream for the Resource.

Returns: an OutputStream to which content can be written.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if OutputStreams are not supported for this Resource type. IOException if the URL cannot be opened.

getSize

public long getSize()
Get the size of this 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.

Returns: hash code as int.

isDirectory

public boolean isDirectory()
Tells if the resource is a directory.

Returns: boolean whether the resource is a directory.

isExists

public boolean isExists()
Find out whether the URL exists .

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.

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.

Returns: a String representation of this URLResource.