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

public Class Resource

extends DataType
implements Comparable<Resource>, ResourceCollection
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.types.ResourceCollection, java.lang.Iterable, java.lang.Comparable
Known Direct Subclasses
org.apache.tools.ant.types.resources.AbstractClasspathResource, org.apache.tools.ant.types.resources.ArchiveResource, org.apache.tools.ant.types.resources.FileResource, org.apache.tools.ant.types.resources.LogOutputResource, org.apache.tools.ant.types.resources.PropertyResource, org.apache.tools.ant.types.resources.ResourceDecorator, org.apache.tools.ant.types.resources.StringResource, org.apache.tools.ant.types.resources.URLResource, org.apache.tools.ant.taskdefs.Concat.ConcatResource
Imports
java.io.IOException, .InputStream, .OutputStream, java.math.BigInteger, java.util.Collections, .Iterator, .Optional, org.apache.tools.ant.types.resources.FileProvider

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, ...).

Since
Ant 1.5.2
See Also
org.apache.tools.ant.types.resources.Touchable

Field Summary

Modifier and TypeField and Description
private Boolean
private Boolean
private Long
protected static final int
MAGIC

Magic number

private String
private static final int
private Long
public static final long
UNKNOWN_DATETIME

Constant unknown datetime for getLastModified

public static final long
UNKNOWN_SIZE

Constant unknown size

Inherited from org.apache.tools.ant.types.DataType:
checkedref

Constructor Summary

AccessConstructor and Description
public
Resource()

Default constructor.

public
Resource(String
relative path of the resource. Expects "/" to be used as the directory separator.
name
)

Only sets the name.

public
Resource(String
relative path of the resource. Expects "/" to be used as the directory separator.
name
,
boolean
if true, this resource exists.
exists
,
long
the last modification time of this resource.
lastmodified
)

Sets the name, lastmodified flag, and exists flag.

public
Resource(String
relative path of the resource. Expects "/" to be used as the directory separator.
name
,
boolean
if true the resource exists
exists
,
long
the last modification time of the resource
lastmodified
,
boolean
if true, this resource is a directory
directory
)

Sets the name, lastmodified flag, exists flag, and directory flag.

public
Resource(String
relative path of the resource. Expects "/" to be used as the directory separator.
name
,
boolean
if true the resource exists
exists
,
long
the last modification time of the resource
lastmodified
,
boolean
if true, this resource is a directory
directory
,
long
the size of this resource.
size
)

Sets the name, lastmodified flag, exists flag, directory flag, and size.

Method Summary

Modifier and TypeMethod and Description
public <
desired type
T
>
T

Returns:

resource of a desired type
as
(Class<T>
a class
clazz
)

Returns a view of this resource that implements the interface given as the argument or null if there is no such view.

public <
desired type
T
>
Optional<T>

Returns:

Optional resource of a desired type
asOptional
(Class<T>
a class
clazz
)

Return as(Class) as an Optional.

public Object

Returns:

copy of this.
clone
()

Overrides org.apache.tools.ant.types.DataType.clone.

Clone this Resource.
public int

Returns:

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

Implements java.lang.Comparable.compareTo.

Delegates to a comparison of names.
public boolean

Returns:

true if the specified Object is equal to this Resource.
equals
(Object
the object to check against.
other
)

Overrides java.lang.Object.equals.

Implement basic Resource equality.
public InputStream

Returns:

an InputStream containing this Resource's content.
getInputStream
()

Get an InputStream for the Resource.

public long

Returns:

the modification time, if that is meaningful (e.g. for a file resource which exists); 0 if the resource does not exist, to mirror the behavior of java.io.File#lastModified; or 0 if the notion of modification time is meaningless for this class of resource (e.g. an inline string)
getLastModified
()

Tells the modification time in milliseconds since 01.01.1970 (the "epoch").

protected static int

Returns:

a magic number as int.
getMagicNumber
(byte[]
byte[] to seed with.
seed
)

Create a "magic number" for use in hashCode calculations.

public String

Returns:

the name of this resource.
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.

public OutputStream

Returns:

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

Get an OutputStream for the Resource.

protected Resource

Returns:

Resource.
getRef
()

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

public long

Returns:

the size, as a long, 0 if the Resource does not exist (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.
getSize
()

Get the size of this Resource.

public int

Returns:

hash code as int.
hashCode
()

Overrides java.lang.Object.hashCode.

Get the hash code for this Resource.
public boolean

Returns:

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

Tells if the resource is a directory.

public boolean

Returns:

true if this resource exists.
isExists
()

The exists attribute tells whether a resource exists.

public boolean

Returns:

whether this Resource is a FileProvider.
isFilesystemOnly
()

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

Fulfill the ResourceCollection contract.
public Iterator<Resource>

Returns:

an Iterator of Resources.
iterator
()

Implements java.lang.Iterable.iterator.

Fulfill the ResourceCollection contract.
public void
setDirectory(boolean
if true, this resource is a directory.
directory
)

Set the directory attribute.

public void
setExists(boolean
if true, this resource exists.
exists
)

Set the exists attribute.

public void
setLastModified(long
the modification time in milliseconds since 01.01.1970.
lastmodified
)

Set the last modification attribute.

public void
setName(String
relative path of the resource. Expects "/" to be used as the directory separator.
name
)

Set the name of this Resource.

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

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

Overrides the base version.
public void
setSize(long
the size, as a long.
size
)

Set the size of this Resource.

public int

Returns:

the size of this ResourceCollection.
size
()

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

Fulfill the ResourceCollection contract.
public final String

Returns:

this Resource formatted as a long String.
toLongString
()

Get a long String representation of this Resource.

public String

Returns:

this Resource formatted as a String.
toString
()

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

Get the string representation of this Resource.
Inherited from org.apache.tools.ant.types.DataType:
checkAttributesAllowedcheckChildrenAllowedcircularReferencedieOnCircularReferencedieOnCircularReferencedieOnCircularReferencegetCheckedRefgetCheckedRefgetCheckedRefgetCheckedRefgetCheckedRefgetDataTypeNamegetRefidinvokeCircularReferenceCheckisCheckedisReferencenoChildrenAllowedpushAndInvokeCircularReferenceChecksetCheckedtooManyAttributes

Field Detail

directoryback to summary
private Boolean directory
existsback to summary
private Boolean exists
lastmodifiedback to summary
private Long lastmodified
MAGICback to summary
protected static final int MAGIC

Magic number

nameback to summary
private String name
NULL_NAMEback to summary
private static final int NULL_NAME
sizeback to summary
private Long size
UNKNOWN_DATETIMEback to summary
public static final long UNKNOWN_DATETIME

Constant unknown datetime for getLastModified

UNKNOWN_SIZEback to summary
public static final long UNKNOWN_SIZE

Constant unknown size

Constructor Detail

Resourceback to summary
public Resource()

Default constructor.

Resourceback to summary
public Resource(String name)

Only sets the name.

This is a dummy, used for not existing resources.

Parameters
name:String

relative path of the resource. Expects "/" to be used as the directory separator.

Resourceback to summary
public Resource(String name, boolean exists, long lastmodified)

Sets the name, lastmodified flag, and exists flag.

Parameters
name:String

relative path of the resource. Expects "/" to be used as the directory separator.

exists:boolean

if true, this resource exists.

lastmodified:long

the last modification time of this resource.

Resourceback to summary
public Resource(String name, boolean exists, long lastmodified, boolean directory)

Sets the name, lastmodified flag, exists flag, and directory flag.

Parameters
name:String

relative path of the resource. Expects "/" to be used as the directory separator.

exists:boolean

if true the resource exists

lastmodified:long

the last modification time of the resource

directory:boolean

if true, this resource is a directory

Resourceback to summary
public Resource(String name, boolean exists, long lastmodified, boolean directory, long size)

Sets the name, lastmodified flag, exists flag, directory flag, and size.

Parameters
name:String

relative path of the resource. Expects "/" to be used as the directory separator.

exists:boolean

if true the resource exists

lastmodified:long

the last modification time of the resource

directory:boolean

if true, this resource is a directory

size:long

the size of this resource.

Method Detail

asback to summary
public <T> T as(Class<T> clazz)

Returns a view of this resource that implements the interface given as the argument or null if there is no such view.

This allows extension interfaces to be added to resources without growing the number of permutations of interfaces decorators/adapters need to implement.

This implementation of the method will return the current instance itself if it can be assigned to the given class.

Parameters
<T>
desired type
clazz:Class<T>

a class

Returns:T

resource of a desired type

Since
Ant 1.8.0
asOptionalback to summary
public <T> Optional<T> asOptional(Class<T> clazz)

Return as(Class) as an Optional.

Parameters
<T>
desired type
clazz:Class<T>

a class

Returns:Optional<T>

Optional resource of a desired type

Since
Ant 1.10.2
cloneback to summary
public Object clone()

Overrides org.apache.tools.ant.types.DataType.clone.

Clone this Resource.

Returns:Object

copy of this.

Annotations
@Override
compareToback to summary
public int compareTo(Resource other)

Implements java.lang.Comparable.compareTo.

Delegates to a comparison of names.

Parameters
other:Resource

the object to compare to.

Returns:int

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

Annotations
@Override
Since
Ant 1.6
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Implement basic Resource equality.

Parameters
other:Object

the object to check against.

Returns:boolean

true if the specified Object is equal to this Resource.

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

Get an InputStream for the Resource.

Returns:InputStream

an InputStream containing this Resource's content.

Exceptions
IOException:
if unable to provide the content of this Resource as a stream.
UnsupportedOperationException:
if InputStreams are not supported for this Resource type.
Since
Ant 1.7
getLastModifiedback to summary
public long getLastModified()

Tells the modification time in milliseconds since 01.01.1970 (the "epoch").

Returns:long

the modification time, if that is meaningful (e.g. for a file resource which exists); 0 if the resource does not exist, to mirror the behavior of java.io.File#lastModified; or 0 if the notion of modification time is meaningless for this class of resource (e.g. an inline string)

getMagicNumberback to summary
protected static int getMagicNumber(byte[] seed)

Create a "magic number" for use in hashCode calculations.

Parameters
seed:byte[]

byte[] to seed with.

Returns:int

a magic number as int.

getNameback to summary
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.

Returns:String

the name of this resource.

getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Get an OutputStream for the Resource.

Returns:OutputStream

an OutputStream to which content can be written.

Exceptions
IOException:
if unable to provide the content of this Resource as a stream.
UnsupportedOperationException:
if OutputStreams are not supported for this Resource type.
Since
Ant 1.7
getRefback to summary
protected Resource getRef()

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

Returns:Resource

Resource.

getSizeback to summary
public long getSize()

Get the size of this Resource.

Returns:long

the size, as a long, 0 if the Resource does not exist (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.

Since
Ant 1.6.3
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Get the hash code for this Resource.

Returns:int

hash code as int.

Annotations
@Override
Since
Ant 1.7
isDirectoryback to summary
public boolean isDirectory()

Tells if the resource is a directory.

Returns:boolean

boolean flag indicating if the resource is a directory.

isExistsback to summary
public boolean isExists()

The exists attribute tells whether a resource exists.

Returns:boolean

true if this resource exists.

isFilesystemOnlyback to summary
public boolean isFilesystemOnly()

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

Fulfill the ResourceCollection contract.

Returns:boolean

whether this Resource is a FileProvider.

Annotations
@Override
Since
Ant 1.7
iteratorback to summary
public Iterator<Resource> iterator()

Implements java.lang.Iterable.iterator.

Fulfill the ResourceCollection contract.

Returns:Iterator<Resource>

an Iterator of Resources.

Annotations
@Override
Since
Ant 1.7
setDirectoryback to summary
public void setDirectory(boolean directory)

Set the directory attribute.

Parameters
directory:boolean

if true, this resource is a directory.

setExistsback to summary
public void setExists(boolean exists)

Set the exists attribute.

Parameters
exists:boolean

if true, this resource exists.

setLastModifiedback to summary
public void setLastModified(long lastmodified)

Set the last modification attribute.

Parameters
lastmodified:long

the modification time in milliseconds since 01.01.1970.

setNameback to summary
public void setName(String name)

Set the name of this Resource.

Parameters
name:String

relative path of the resource. Expects "/" to be used as the directory separator.

setRefidback to summary
public void setRefid(Reference r)

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

Overrides the base version.

Parameters
r:Reference

the Reference to set.

Annotations
@Override
setSizeback to summary
public void setSize(long size)

Set the size of this Resource.

Parameters
size:long

the size, as a long.

Since
Ant 1.6.3
sizeback to summary
public int size()

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

Fulfill the ResourceCollection contract.

Returns:int

the size of this ResourceCollection.

Annotations
@Override
Since
Ant 1.7
toLongStringback to summary
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.

Returns:String

this Resource formatted as a long String.

Since
Ant 1.7
toStringback to summary
public String toString()

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

Get the string representation of this Resource.

Returns:String

this Resource formatted as a String.

Annotations
@Override
Since
Ant 1.7