Class FileResource
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.types.DataType
org.apache.tools.ant.types.Resource
org.apache.tools.ant.types.resources.FileResource
- All Implemented Interfaces:
Cloneable
,Comparable<Resource>
,Iterable<Resource>
,ResourceCollection
,ResourceFactory
,Appendable
,FileProvider
,Touchable
public class FileResource
extends Resource
implements Touchable, FileProvider, ResourceFactory, Appendable
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.ProjectComponent
description, location, project
-
Constructor Summary
ConstructorDescriptionDefault 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, File f) Create a new FileResource.FileResource
(Project p, String s) Constructor for Ant attribute introspection. -
Method Summary
Modifier and TypeMethodDescriptionint
Compare this FileResource to another Resource.boolean
Compare another Object to this FileResource for equality.Get an appending OutputStream.Return the basedir to which the name is relative.getFile()
Get the file represented by this FileResource.Return an InputStream for reading the contents of this Resource.long
Get the modification time in milliseconds since 01.01.1970 .getName()
Get the name of this FileResource.protected File
Get the file represented by this FileResource, ensuring it is not null.Get an OutputStream for the Resource.protected FileResource
getRef()
Perform the check for circular references and return the referenced Resource.getResource
(String path) Create a new resource that matches a relative or absolute path.long
getSize()
Get the size of this Resource.int
hashCode()
Get the hash code for this Resource.boolean
Learn whether the resource is a directory.boolean
isExists()
Learn whether this file exists.boolean
Fulfill the ResourceCollection contract.void
setBaseDir
(File b) Set the basedir for this FileResource.void
Set the File for this FileResource.void
Overrides the super version.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
as, asOptional, clone, getMagicNumber, iterator, setDirectory, setExists, setLastModified, setName, setSize, size, toLongString
Methods inherited from class org.apache.tools.ant.types.DataType
checkAttributesAllowed, checkChildrenAllowed, circularReference, dieOnCircularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes
Methods inherited from class org.apache.tools.ant.ProjectComponent
getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.apache.tools.ant.types.ResourceCollection
isEmpty, stream
-
Constructor Details
-
FileResource
public FileResource()Default constructor. -
FileResource
-
FileResource
Construct a new FileResource from a File.- Parameters:
f
- the File represented.
-
FileResource
-
FileResource
-
-
Method Details
-
setFile
Set the File for this FileResource.- Parameters:
f
- the File to be represented.
-
getFile
Get the file represented by this FileResource.- Specified by:
getFile
in interfaceFileProvider
- Returns:
- the File.
-
setBaseDir
Set the basedir for this FileResource.- Parameters:
b
- the basedir as File.
-
getBaseDir
Return the basedir to which the name is relative.- Returns:
- the basedir as File.
-
setRefid
-
getName
-
isExists
-
getLastModified
public long getLastModified()Get the modification time in milliseconds since 01.01.1970 .- Overrides:
getLastModified
in classResource
- Returns:
- 0 if the resource does not exist.
-
isDirectory
public boolean isDirectory()Learn whether the resource is a directory.- Overrides:
isDirectory
in classResource
- Returns:
- boolean flag indicating if the resource is a directory.
-
getSize
-
getInputStream
Return an InputStream for reading the contents of this Resource.- Overrides:
getInputStream
in classResource
- Returns:
- an InputStream object.
- Throws:
IOException
- if an error occurs.
-
getOutputStream
Get an OutputStream for the Resource.- Overrides:
getOutputStream
in classResource
- 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.
-
getAppendOutputStream
Get an appending OutputStream.- Specified by:
getAppendOutputStream
in interfaceAppendable
- Returns:
- OutputStream
- Throws:
IOException
- if anything goes wrong
-
compareTo
Compare this FileResource to another Resource.- Specified by:
compareTo
in interfaceComparable<Resource>
- Overrides:
compareTo
in classResource
- 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
-
hashCode
-
toString
-
isFilesystemOnly
public boolean isFilesystemOnly()Fulfill the ResourceCollection contract.- Specified by:
isFilesystemOnly
in interfaceResourceCollection
- Overrides:
isFilesystemOnly
in classResource
- Returns:
- whether this Resource is a FileResource.
-
touch
-
getNotNullFile
Get the file represented by this FileResource, ensuring it is not null.- Returns:
- the not-null File.
- Throws:
BuildException
- if file is null.
-
getResource
Create a new resource that matches a relative or absolute path. If the current instance has a compatible baseDir attribute, it is copied.- Specified by:
getResource
in interfaceResourceFactory
- Parameters:
path
- relative/absolute path to a resource- Returns:
- a new resource of type FileResource
- Throws:
BuildException
- if desired- Since:
- Ant1.8
-
getRef
Description copied from class:Resource
Perform the check for circular references and return the referenced Resource.
-