org.apache.tools.ant.types
Class Resource

java.lang.Object
  |
  +--org.apache.tools.ant.types.Resource
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable

public class Resource
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable

Describes a File or a ZipEntry. This class is meant to be used by classes needing to record path and date/time information about a file, a zip entry or some similar resource (URL, archive in a version control repository, ...).

Since:
Ant 1.5.2

Field Summary
static long UNKNOWN_SIZE
          Constant unknown size
 
Constructor Summary
Resource()
          Default constructor.
Resource(java.lang.String name)
          Only sets the name.
Resource(java.lang.String name, boolean exists, long lastmodified)
          Sets the name, lastmodified flag, and exists flag.
Resource(java.lang.String name, boolean exists, long lastmodified, boolean directory)
          Sets the name, lastmodified flag, exists flag, and directory flag.
Resource(java.lang.String name, boolean exists, long lastmodified, boolean directory, long size)
          Sets the name, lastmodified flag, exists flag, directory flag, and size.
 
Method Summary
 java.lang.Object clone()
          Clone this Resource.
 int compareTo(java.lang.Object other)
          Delegates to a comparison of names.
 long getLastModified()
          Tells the modification time in milliseconds since 01.01.1970 .
 java.lang.String getName()
          Name attribute will contain the path of a file relative to the root directory of its fileset or the recorded path of a zip entry.
 long getSize()
          Get the size of this Resource.
 boolean isDirectory()
          Tells if the resource is a directory.
 boolean isExists()
          The exists attribute tells whether a file exists.
 void setDirectory(boolean directory)
          Set the directory attribute.
 void setExists(boolean exists)
          Set the exists attribute.
 void setLastModified(long lastmodified)
          Set the last modification attribute.
 void setName(java.lang.String name)
          Set the name of this Resource.
 void setSize(long size)
          Set the size of this Resource.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_SIZE

public static final long UNKNOWN_SIZE
Constant unknown size

See Also:
Constant Field Values
Constructor Detail

Resource

public Resource()
Default constructor.


Resource

public Resource(java.lang.String name)
Only sets the name.

This is a dummy, used for not existing resources.

Parameters:
name - relative path of the resource. Expects "/" to be used as the directory separator.

Resource

public Resource(java.lang.String name,
                boolean exists,
                long lastmodified)
Sets the name, lastmodified flag, and exists flag.

Parameters:
name - relative path of the resource. Expects "/" to be used as the directory separator.
exists - if true, this resource exists.
lastmodified - the last modification time of this resource.

Resource

public Resource(java.lang.String name,
                boolean exists,
                long lastmodified,
                boolean directory)
Sets the name, lastmodified flag, exists flag, and directory flag.

Parameters:
name - relative path of the resource. Expects "/" to be used as the directory separator.
exists - if true the resource exists
lastmodified - the last modification time of the resource
directory - if true, this resource is a directory

Resource

public Resource(java.lang.String name,
                boolean exists,
                long lastmodified,
                boolean directory,
                long size)
Sets the name, lastmodified flag, exists flag, directory flag, and size.

Parameters:
name - relative path of the resource. Expects "/" to be used as the directory separator.
exists - if true the resource exists
lastmodified - the last modification time of the resource
directory - if true, this resource is a directory
size - the size of this resource.
Method Detail

getName

public java.lang.String getName()
Name attribute will contain the path of a file relative to the root directory of its fileset or the recorded path of a zip entry.

example for a file with fullpath /var/opt/adm/resource.txt in a file set with root dir /var/opt it will be adm/resource.txt.

"/" will be used as the directory separator.

Returns:
the name of this resource.

setName

public void setName(java.lang.String name)
Set the name of this Resource.

Parameters:
name - relative path of the resource. Expects "/" to be used as the directory separator.

isExists

public boolean isExists()
The exists attribute tells whether a file exists.

Returns:
true if this resource exists.

setExists

public void setExists(boolean exists)
Set the exists attribute.

Parameters:
exists - if true, this resource exists.

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 File.

setLastModified

public void setLastModified(long lastmodified)
Set the last modification attribute.

Parameters:
lastmodified - the modification time in milliseconds since 01.01.1970.

isDirectory

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

Returns:
boolean flag indicating if the resource is a directory.

setDirectory

public void setDirectory(boolean directory)
Set the directory attribute.

Parameters:
directory - if true, this resource is a directory.

setSize

public void setSize(long size)
Set the size of this Resource.

Parameters:
size - the size, as a long.
Since:
Ant 1.6.3

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.
Since:
Ant 1.6.3

clone

public java.lang.Object clone()
Clone this Resource.

Overrides:
clone in class java.lang.Object
Returns:
copy of this.

compareTo

public int compareTo(java.lang.Object other)
Delegates to a comparison of names.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - the object to compare to.
Returns:
a negative integer, zero, or a positive integer as this Resource is less than, equal to, or greater than the specified Resource.
Since:
Ant 1.6


Copyright 2000-2005 Apache Software Foundation. All Rights Reserved.