Top Description Fields Constructors Methods
org.apache.tools.ant.types.resources

public Class FileResource

extends Resource
implements Touchable, FileProvider, ResourceFactory, Appendable
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.types.resources.Appendable, org.apache.tools.ant.types.ResourceFactory, org.apache.tools.ant.types.resources.FileProvider, org.apache.tools.ant.types.resources.Touchable
Imports
java.io.File, .IOException, .InputStream, .OutputStream, java.nio.file.Files, org.apache.tools.ant.BuildException, .Project, org.apache.tools.ant.types.Reference, .Resource, .ResourceFactory, org.apache.tools.ant.util.FileUtils

A Resource representation of a File.
Since
Ant 1.7

Field Summary

Modifier and TypeField and Description
private File
private File
private static final FileUtils
private static final int
Inherited from org.apache.tools.ant.types.Resource:
MAGICUNKNOWN_DATETIMEUNKNOWN_SIZE

Constructor Summary

AccessConstructor and Description
public
FileResource()

Default constructor.

public
FileResource(File
the basedir as File.
b
,
String
the relative filename.
name
)

Construct a new FileResource using the specified basedir and relative name.

public
FileResource(File
the File represented.
f
)

Construct a new FileResource from a File.

public
FileResource(Project
Project
p
,
File
File represented
f
)

Create a new FileResource.

public
FileResource(Project
the Project against which to resolve s.
p
,
String
the absolute or Project-relative filename as a String.
s
)

Constructor for Ant attribute introspection.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

a negative integer, zero, or a positive integer as this FileResource is less than, equal to, or greater than the specified Resource.
compareTo
(Resource
the other Resource against which to compare.
another
)

Overrides org.apache.tools.ant.types.Resource.compareTo.

Implements java.lang.Comparable.compareTo.

Compare this FileResource to another Resource.
public boolean

Returns:

true if another is a FileResource representing the same file.
equals
(Object
the other Object to compare.
another
)

Overrides org.apache.tools.ant.types.Resource.equals.

Compare another Object to this FileResource for equality.
public OutputStream
public File

Returns:

the basedir as File.
getBaseDir
()

Return the basedir to which the name is relative.

public File

Returns:

the File.
getFile
()

Implements org.apache.tools.ant.types.resources.FileProvider.getFile.

Get the file represented by this FileResource.
public InputStream

Returns:

an InputStream object.
getInputStream
()

Overrides org.apache.tools.ant.types.Resource.getInputStream.

Return an InputStream for reading the contents of this Resource.
public long

Returns:

0 if the resource does not exist.
getLastModified
()

Overrides org.apache.tools.ant.types.Resource.getLastModified.

Get the modification time in milliseconds since 01.01.1970 .
public String

Returns:

the name of this resource.
getName
()

Overrides org.apache.tools.ant.types.Resource.getName.

Get the name of this FileResource.
protected File

Returns:

the not-null File.
getNotNullFile
()

Get the file represented by this FileResource, ensuring it is not null.

public OutputStream

Returns:

an OutputStream to which content can be written.
getOutputStream
()

Overrides org.apache.tools.ant.types.Resource.getOutputStream.

Get an OutputStream for the Resource.
private OutputStream
getOutputStream(boolean append)

protected FileResource
getRef()

Overrides org.apache.tools.ant.types.Resource.getRef.

Perform the check for circular references and return the referenced Resource.
public Resource

Returns:

a new resource of type FileResource
getResource
(String
relative/absolute path to a resource
path
)

Implements org.apache.tools.ant.types.ResourceFactory.getResource.

Create a new resource that matches a relative or absolute path.
public long

Returns:

the size, as a long, 0 if the Resource does not exist.
getSize
()

Overrides org.apache.tools.ant.types.Resource.getSize.

Get the size of this Resource.
public int

Returns:

hash code as int.
hashCode
()

Overrides org.apache.tools.ant.types.Resource.hashCode.

Get the hash code for this Resource.
public boolean

Returns:

boolean flag indicating if the resource is a directory.
isDirectory
()

Overrides org.apache.tools.ant.types.Resource.isDirectory.

Learn whether the resource is a directory.
public boolean

Returns:

true if this resource exists.
isExists
()

Overrides org.apache.tools.ant.types.Resource.isExists.

Learn whether this file exists.
public boolean

Returns:

whether this Resource is a FileResource.
isFilesystemOnly
()

Overrides org.apache.tools.ant.types.Resource.isFilesystemOnly.

Implements org.apache.tools.ant.types.ResourceCollection.isFilesystemOnly.

Fulfill the ResourceCollection contract.
public void
setBaseDir(File
the basedir as File.
b
)

Set the basedir for this FileResource.

public void
setFile(File
the File to be represented.
f
)

Set the File for this FileResource.

public void
setRefid(Reference
the Reference to set.
r
)

Overrides org.apache.tools.ant.types.Resource.setRefid.

Overrides the super version.
public String

Returns:

this FileResource formatted as a String.
toString
()

Overrides org.apache.tools.ant.types.Resource.toString.

Get the string representation of this Resource.
public void
touch(long
new last modification time.
modTime
)

Implements org.apache.tools.ant.types.resources.Touchable.touch.

Implement the Touchable interface.
Inherited from org.apache.tools.ant.types.Resource:
asasOptionalclonegetMagicNumberiteratorsetDirectorysetExistssetLastModifiedsetNamesetSizesizetoLongString

Field Detail

baseDirback to summary
private File baseDir
fileback to summary
private File file
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
NULL_FILEback to summary
private static final int NULL_FILE

Constructor Detail

FileResourceback to summary
public FileResource()

Default constructor.

FileResourceback to summary
public FileResource(File b, String name)

Construct a new FileResource using the specified basedir and relative name.

Parameters
b:File

the basedir as File.

name:String

the relative filename.

FileResourceback to summary
public FileResource(File f)

Construct a new FileResource from a File.

Parameters
f:File

the File represented.

FileResourceback to summary
public FileResource(Project p, File f)

Create a new FileResource.

Parameters
p:Project

Project

f:File

File represented

Since
Ant 1.8
FileResourceback to summary
public FileResource(Project p, String s)

Constructor for Ant attribute introspection.

Parameters
p:Project

the Project against which to resolve s.

s:String

the absolute or Project-relative filename as a String.

See Also
org.apache.tools.ant.IntrospectionHelper

Method Detail

compareToback to summary
public int compareTo(Resource another)

Overrides org.apache.tools.ant.types.Resource.compareTo.

Implements java.lang.Comparable.compareTo.

Compare this FileResource to another Resource.

Parameters
another:Resource

the other Resource against which to compare.

Returns:int

a negative integer, zero, or a positive integer as this FileResource is less than, equal to, or greater than the specified Resource.

Annotations
@Override
equalsback to summary
public boolean equals(Object another)

Overrides org.apache.tools.ant.types.Resource.equals.

Compare another Object to this FileResource for equality.

Parameters
another:Object

the other Object to compare.

Returns:boolean

true if another is a FileResource representing the same file.

Annotations
@Override
getAppendOutputStreamback to summary
public OutputStream getAppendOutputStream() throws IOException

Implements org.apache.tools.ant.types.resources.Appendable.getAppendOutputStream.

Doc from org.apache.tools.ant.types.resources.Appendable.getAppendOutputStream.

Get an appending OutputStream.

Returns:OutputStream

OutputStream

Annotations
@Override
Exceptions
IOException:
if anything goes wrong
getBaseDirback to summary
public File getBaseDir()

Return the basedir to which the name is relative.

Returns:File

the basedir as File.

getFileback to summary
public File getFile()

Implements org.apache.tools.ant.types.resources.FileProvider.getFile.

Get the file represented by this FileResource.

Returns:File

the File.

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Overrides org.apache.tools.ant.types.Resource.getInputStream.

Return an InputStream for reading the contents of this Resource.

Returns:InputStream

an InputStream object.

Annotations
@Override
Exceptions
IOException:
if an error occurs.
getLastModifiedback to summary
public long getLastModified()

Overrides org.apache.tools.ant.types.Resource.getLastModified.

Get the modification time in milliseconds since 01.01.1970 .

Returns:long

0 if the resource does not exist.

Annotations
@Override
getNameback to summary
public String getName()

Overrides org.apache.tools.ant.types.Resource.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:String

the name of this resource.

Annotations
@Override
getNotNullFileback to summary
protected File getNotNullFile()

Get the file represented by this FileResource, ensuring it is not null.

Returns:File

the not-null File.

Exceptions
BuildException:
if file is null.
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Overrides org.apache.tools.ant.types.Resource.getOutputStream.

Get an OutputStream for the Resource.

Returns:OutputStream

an OutputStream to which content can be written.

Annotations
@Override
Exceptions
IOException:
if unable to provide the content of this Resource as a stream.
UnsupportedOperationException:
if OutputStreams are not supported for this Resource type.
getOutputStreamback to summary
private OutputStream getOutputStream(boolean append) throws IOException
getRefback to summary
protected FileResource getRef()

Overrides org.apache.tools.ant.types.Resource.getRef.

Doc from org.apache.tools.ant.types.Resource.getRef.

Perform the check for circular references and return the referenced Resource.

Returns:FileResource

Resource.

Annotations
@Override
getResourceback to summary
public Resource getResource(String path)

Implements org.apache.tools.ant.types.ResourceFactory.getResource.

Create a new resource that matches a relative or absolute path. If the current instance has a compatible baseDir attribute, it is copied.

Parameters
path:String

relative/absolute path to a resource

Returns:Resource

a new resource of type FileResource

Annotations
@Override
Exceptions
BuildException:
if desired
Since
Ant1.8
getSizeback to summary
public long getSize()

Overrides org.apache.tools.ant.types.Resource.getSize.

Get the size of this Resource.

Returns:long

the size, as a long, 0 if the Resource does not exist.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides org.apache.tools.ant.types.Resource.hashCode.

Get the hash code for this Resource.

Returns:int

hash code as int.

Annotations
@Override
isDirectoryback to summary
public boolean isDirectory()

Overrides org.apache.tools.ant.types.Resource.isDirectory.

Learn whether the resource is a directory.

Returns:boolean

boolean flag indicating if the resource is a directory.

Annotations
@Override
isExistsback to summary
public boolean isExists()

Overrides org.apache.tools.ant.types.Resource.isExists.

Learn whether this file exists.

Returns:boolean

true if this resource exists.

Annotations
@Override
isFilesystemOnlyback to summary
public boolean isFilesystemOnly()

Overrides org.apache.tools.ant.types.Resource.isFilesystemOnly.

Implements org.apache.tools.ant.types.ResourceCollection.isFilesystemOnly.

Fulfill the ResourceCollection contract.

Returns:boolean

whether this Resource is a FileResource.

Annotations
@Override
setBaseDirback to summary
public void setBaseDir(File b)

Set the basedir for this FileResource.

Parameters
b:File

the basedir as File.

setFileback to summary
public void setFile(File f)

Set the File for this FileResource.

Parameters
f:File

the File to be represented.

setRefidback to summary
public void setRefid(Reference r)

Overrides org.apache.tools.ant.types.Resource.setRefid.

Overrides the super version.

Parameters
r:Reference

the Reference to set.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.apache.tools.ant.types.Resource.toString.

Get the string representation of this Resource.

Returns:String

this FileResource formatted as a String.

Annotations
@Override
touchback to summary
public void touch(long modTime)

Implements org.apache.tools.ant.types.resources.Touchable.touch.

Implement the Touchable interface.

Parameters
modTime:long

new last modification time.

Annotations
@Override