org.apache.tools.ant.types
Class Resource
- Cloneable, Comparable, ResourceCollection
Describes a "File-like" resource (File, ZipEntry, etc.).
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, ...).
Resource() - Default constructor.
|
Resource(String name) - Only sets the name.
|
Resource(String name, boolean exists, long lastmodified) - Sets the name, lastmodified flag, and exists flag.
|
Resource(String name, boolean exists, long lastmodified, boolean directory) - Sets the name, lastmodified flag, exists flag, and directory flag.
|
Resource(String name, boolean exists, long lastmodified, boolean directory, long size) - Sets the name, lastmodified flag, exists flag, directory flag, and size.
|
Object | clone() - Clone this Resource.
|
int | compareTo(Object other) - Delegates to a comparison of names.
|
boolean | equals(Object other) - Implement basic Resource equality.
|
InputStream | getInputStream() - Get an InputStream for the Resource.
|
long | getLastModified() - Tells the modification time in milliseconds since 01.01.1970 .
|
protected static int | getMagicNumber(byte[] seed) - Create a "magic number" for use in hashCode calculations.
|
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.
|
OutputStream | getOutputStream() - Get an OutputStream for the Resource.
|
long | getSize() - Get the size of this Resource.
|
int | hashCode() - Get the hash code for this Resource.
|
boolean | isDirectory() - Tells if the resource is a directory.
|
boolean | isExists() - The exists attribute tells whether a file exists.
|
boolean | isFilesystemOnly() - Fulfill the ResourceCollection contract.
|
Iterator | iterator() - Fulfill the ResourceCollection contract.
|
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(String name) - Set the name of this Resource.
|
void | setRefid(Reference r) - Overrides the base version.
|
void | setSize(long size) - Set the size of this Resource.
|
int | size() - Fulfill the ResourceCollection contract.
|
String | toLongString() - Get a long String representation of this Resource.
|
String | toString() - Get the string representation of this Resource.
|
checkAttributesAllowed , checkChildrenAllowed , circularReference , clone , dieOnCircularReference , dieOnCircularReference , dieOnCircularReference , getCheckedRef , getCheckedRef , getCheckedRef , getCheckedRef , getDataTypeName , getRefid , invokeCircularReferenceCheck , isChecked , isReference , noChildrenAllowed , setChecked , setRefid , toString , tooManyAttributes |
MAGIC
protected static final int MAGIC
Magic number
UNKNOWN_DATETIME
public static final long UNKNOWN_DATETIME
Constant unknown datetime for getLastModified
UNKNOWN_SIZE
public static final long UNKNOWN_SIZE
Constant unknown size
Resource
public Resource()
Default constructor.
Resource
public Resource(String name)
Only sets the name.
This is a dummy, used for not existing resources.
name
- relative path of the resource. Expects
"/" to be used as the directory separator.
Resource
public Resource(String name,
boolean exists,
long lastmodified)
Sets the name, lastmodified flag, and exists flag.
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(String name,
boolean exists,
long lastmodified,
boolean directory)
Sets the name, lastmodified flag, exists flag, and directory flag.
name
- relative path of the resource. Expects
"/" to be used as the directory separator.exists
- if true the resource existslastmodified
- the last modification time of the resourcedirectory
- if true, this resource is a directory
Resource
public Resource(String name,
boolean exists,
long lastmodified,
boolean directory,
long size)
Sets the name, lastmodified flag, exists flag, directory flag, and size.
name
- relative path of the resource. Expects
"/" to be used as the directory separator.exists
- if true the resource existslastmodified
- the last modification time of the resourcedirectory
- if true, this resource is a directorysize
- the size of this resource.
clone
public Object clone()
Clone this Resource.
- clone in interface DataType
compareTo
public int compareTo(Object other)
Delegates to a comparison of names.
other
- the object to compare to.
- a negative integer, zero, or a positive integer as this Resource
is less than, equal to, or greater than the specified Resource.
equals
public boolean equals(Object other)
Implement basic Resource equality.
other
- the object to check against.
- true if the specified Object is equal to this Resource.
getInputStream
public InputStream getInputStream()
throws IOException
Get an InputStream for the Resource.
- an InputStream containing this Resource's content.
getLastModified
public long getLastModified()
Tells the modification time in milliseconds since 01.01.1970 .
- 0 if the resource does not exist to mirror the behavior
of
File
.
getMagicNumber
protected static int getMagicNumber(byte[] seed)
Create a "magic number" for use in hashCode calculations.
seed
- byte[] to seed with.
getName
public 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.
- the name of this resource.
getOutputStream
public OutputStream getOutputStream()
throws IOException
Get an OutputStream for the Resource.
- an OutputStream to which content can be written.
getSize
public long getSize()
Get the size of this Resource.
- the size, as a long, 0 if the Resource does not exist (for
compatibility with java.io.File), or UNKNOWN_SIZE if not known.
hashCode
public int hashCode()
Get the hash code for this Resource.
isDirectory
public boolean isDirectory()
Tells if the resource is a directory.
- boolean flag indicating if the resource is a directory.
isExists
public boolean isExists()
The exists attribute tells whether a file exists.
- true if this resource exists.
isFilesystemOnly
public boolean isFilesystemOnly()
Fulfill the ResourceCollection contract.
- isFilesystemOnly in interface ResourceCollection
- whether this Resource is a FileResource.
iterator
public Iterator iterator()
Fulfill the ResourceCollection contract.
- iterator in interface ResourceCollection
- an Iterator of Resources.
setDirectory
public void setDirectory(boolean directory)
Set the directory attribute.
directory
- if true, this resource is a directory.
setExists
public void setExists(boolean exists)
Set the exists attribute.
exists
- if true, this resource exists.
setLastModified
public void setLastModified(long lastmodified)
Set the last modification attribute.
lastmodified
- the modification time in milliseconds since 01.01.1970.
setName
public void setName(String name)
Set the name of this Resource.
name
- relative path of the resource. Expects
"/" to be used as the directory separator.
setRefid
public void setRefid(Reference r)
Overrides the base version.
- setRefid in interface DataType
r
- the Reference to set.
setSize
public void setSize(long size)
Set the size of this Resource.
size
- the size, as a long.
size
public int size()
Fulfill the ResourceCollection contract.
- size in interface ResourceCollection
- the size of this ResourceCollection.
toLongString
public final String toLongString()
Get a long String representation of this Resource.
This typically should be the value of toString()
prefixed by a type description.
- this Resource formatted as a long String.
toString
public String toString()
Get the string representation of this Resource.
- toString in interface DataType
- this Resource formatted as a String.