org.apache.tools.ant.types.resources

Class FileResource

public class FileResource extends Resource implements Touchable, FileProvider, ResourceFactory, Appendable

A Resource representation of a File.

Since: Ant 1.7

Constructor Summary
FileResource()
Default constructor.
FileResource(File b, String name)
Construct a new FileResource using the specified basedir and relative name.
FileResource(File f)
Construct a new FileResource from a File.
FileResource(Project p, File f)
Create a new FileResource.
FileResource(Project p, String s)
Constructor for Ant attribute introspection.
Method Summary
intcompareTo(Object another)
Compare this FileResource to another Resource.
booleanequals(Object another)
Compare another Object to this FileResource for equality.
OutputStreamgetAppendOutputStream()
FilegetBaseDir()
Return the basedir to which the name is relative.
FilegetFile()
Get the file represented by this FileResource.
InputStreamgetInputStream()
Return an InputStream for reading the contents of this Resource.
longgetLastModified()
Get the modification time in milliseconds since 01.01.1970 .
StringgetName()
Get the name of this FileResource.
protected FilegetNotNullFile()
Get the file represented by this FileResource, ensuring it is not null.
OutputStreamgetOutputStream()
Get an OutputStream for the Resource.
ResourcegetResource(String path)
Create a new resource that matches a relative or absolute path.
longgetSize()
Get the size of this Resource.
inthashCode()
Get the hash code for this Resource.
booleanisDirectory()
Learn whether the resource is a directory.
booleanisExists()
Learn whether this file exists.
booleanisFilesystemOnly()
Fulfill the ResourceCollection contract.
voidsetBaseDir(File b)
Set the basedir for this FileResource.
voidsetFile(File f)
Set the File for this FileResource.
voidsetRefid(Reference r)
Overrides the super version.
StringtoString()
Get the string representation of this Resource.
voidtouch(long modTime)
Implement the Touchable interface.

Constructor Detail

FileResource

public FileResource()
Default constructor.

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(File f)
Construct a new FileResource from a File.

Parameters: f the File represented.

FileResource

public FileResource(Project p, File f)
Create a new FileResource.

Parameters: p Project f File represented

Since: Ant 1.8

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.

See Also: IntrospectionHelper

Method Detail

compareTo

public int compareTo(Object another)
Compare this FileResource to another 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.

Parameters: another the other Object to compare.

Returns: true if another is a FileResource representing the same file.

getAppendOutputStream

public OutputStream getAppendOutputStream()
{@inheritDoc }

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()
Return an InputStream for reading the contents of this Resource.

Returns: an InputStream object.

Throws: IOException if an error occurs.

getLastModified

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

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.

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.

Throws: BuildException if file is null.

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.

getResource

public Resource getResource(String path)
Create a new resource that matches a relative or absolute path. If the current instance has a baseDir attribute, it is copied.

Parameters: path relative/absolute path to a resource

Returns: a new resource of type FileResource

Throws: BuildException if desired

Since: Ant1.8

getSize

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

Returns: hash code as int.

isDirectory

public boolean isDirectory()
Learn whether the resource is a directory.

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

isExists

public boolean isExists()
Learn whether this file exists.

Returns: true if this resource exists.

isFilesystemOnly

public boolean isFilesystemOnly()
Fulfill the ResourceCollection contract.

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.

Parameters: r the Reference to set.

toString

public String toString()
Get the string representation of this Resource.

Returns: this FileResource formatted as a String.

touch

public void touch(long modTime)
Implement the Touchable interface.

Parameters: modTime new last modification time.