org.apache.tools.ant.types.resources

Class FileResource

Implemented Interfaces:
Cloneable, Comparable, ResourceCollection, Touchable

public class FileResource
extends Resource
implements Touchable

A Resource representation of a File.
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

FileResource()
Default constructor.
FileResource(File f)
Construct a new FileResource from a File.
FileResource(File b, String name)
Construct a new FileResource using the specified basedir and relative name.
FileResource(Project p, String s)
Constructor for Ant attribute introspection.

Method Summary

int
compareTo(Object another)
Compare this FileResource to another Resource.
boolean
equals(Object another)
Compare another Object to this FileResource for equality.
File
getBaseDir()
Return the basedir to which the name is relative.
File
getFile()
Get the file represented by this FileResource.
InputStream
getInputStream()
Return an InputStream for reading the contents of this Resource.
long
getLastModified()
Get the modification time in milliseconds since 01.01.1970 .
String
getName()
Get the name of this FileResource.
protected File
getNotNullFile()
Get the file represented by this FileResource, ensuring it is not null.
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()
Learn whether the resource is a directory.
boolean
isExists()
Learn whether this file exists.
boolean
isFilesystemOnly()
Fulfill the ResourceCollection contract.
void
setBaseDir(File b)
Set the basedir for this FileResource.
void
setFile(File f)
Set the File for this FileResource.
void
setRefid(Reference r)
Overrides the super version.
String
toString()
Get the string representation of this Resource.
void
touch(long modTime)
Implement the Touchable interface.

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

FileResource

public FileResource()
Default constructor.

FileResource

public FileResource(File f)
Construct a new FileResource from a File.
Parameters:
f - the File represented.

FileResource

public FileResource(File b,
                    String name)
Construct a new FileResource using the specified basedir and relative name.
Parameters:
b - the basedir as File.
name - the relative filename.

FileResource

public FileResource(Project p,
                    String s)
Constructor for Ant attribute introspection.
Parameters:
p - the Project against which to resolve s.
s - the absolute or Project-relative filename as a String.

Method Details

compareTo

public int compareTo(Object another)
Compare this FileResource to another Resource.
Overrides:
compareTo in interface Resource
Parameters:
another - the other Resource against which to compare.
Returns:
a negative integer, zero, or a positive integer as this FileResource is less than, equal to, or greater than the specified Resource.

equals

public boolean equals(Object another)
Compare another Object to this FileResource for equality.
Overrides:
equals in interface Resource
Parameters:
another - the other Object to compare.
Returns:
true if another is a FileResource representing the same file.

getBaseDir

public File getBaseDir()
Return the basedir to which the name is relative.
Returns:
the basedir as File.

getFile

public File getFile()
Get the file represented by this FileResource.
Returns:
the File.

getInputStream

public InputStream getInputStream()
            throws IOException
Return an InputStream for reading the contents of this Resource.
Overrides:
getInputStream in interface Resource
Returns:
an InputStream object.

getLastModified

public long getLastModified()
Get the modification time in milliseconds since 01.01.1970 .
Overrides:
getLastModified in interface Resource
Returns:
0 if the resource does not exist.

getName

public String getName()
Get the name of this FileResource. If the basedir is set, the name will be relative to that. Otherwise the basename only will be returned.
Overrides:
getName in interface Resource
Returns:
the name of this resource.

getNotNullFile

protected File getNotNullFile()
Get the file represented by this FileResource, ensuring it is not null.
Returns:
the not-null File.

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.

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()
Learn whether the resource is a directory.
Overrides:
isDirectory in interface Resource
Returns:
boolean flag indicating if the resource is a directory.

isExists

public boolean isExists()
Learn whether this file exists.
Overrides:
isExists in interface Resource
Returns:
true if this resource exists.

isFilesystemOnly

public boolean isFilesystemOnly()
Fulfill the ResourceCollection contract.
Specified by:
isFilesystemOnly in interface ResourceCollection
Overrides:
isFilesystemOnly in interface Resource
Returns:
whether this Resource is a FileResource.

setBaseDir

public void setBaseDir(File b)
Set the basedir for this FileResource.
Parameters:
b - the basedir as File.

setFile

public void setFile(File f)
Set the File for this FileResource.
Parameters:
f - the File to be represented.

setRefid

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

toString

public String toString()
Get the string representation of this Resource.
Overrides:
toString in interface Resource
Returns:
this FileResource formatted as a String.

touch

public void touch(long modTime)
Implement the Touchable interface.
Specified by:
touch in interface Touchable
Parameters:
modTime - new last modification time.