org.apache.tools.ant.types.resources

Class StringResource

Implemented Interfaces:
Cloneable, Comparable, ResourceCollection

public class StringResource
extends Resource

Exposes a string as a Resource.
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

StringResource()
Default constructor.
StringResource(String value)
Construct a StringResource with the supplied value.
StringResource(Project project, String value)
Construct a StringResource with the supplied project and value, doing property replacement against the project if non-null.

Method Summary

void
addText(String text)
Add nested text to this resource.
protected String
getContent()
Get the content of this StringResource.
String
getEncoding()
Get the encoding used by this StringResource.
InputStream
getInputStream()
Get an InputStream for the Resource.
String
getName()
Synchronize access.
OutputStream
getOutputStream()
Get an OutputStream for the Resource.
long
getSize()
Get the size of this Resource.
String
getValue()
Get the value of this StringResource, resolving to the root reference if needed.
int
hashCode()
Get the hash code for this Resource.
boolean
isExists()
The exists attribute tells whether a resource exists.
void
setEncoding(String s)
Set the encoding to be used for this StringResource.
void
setName(String s)
Enforce String immutability.
void
setRefid(Reference r)
Overrides the super version.
void
setValue(String s)
The value attribute is a semantically superior alias for the name attribute.
String
toString()
Get the string.

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

StringResource

public StringResource()
Default constructor.

StringResource

public StringResource(String value)
Construct a StringResource with the supplied value.
Parameters:
value - the value of this StringResource.

StringResource

public StringResource(Project project,
                      String value)
Construct a StringResource with the supplied project and value, doing property replacement against the project if non-null.
Parameters:
project - the owning Project.
value - the value of this StringResource.

Method Details

addText

public void addText(String text)
Add nested text to this resource. Properties will be expanded during this process.
Parameters:
text - text to use as the string resource
Since:
Ant 1.7.1

getContent

protected String getContent()
Returns:
a String or null if there is no value.

getEncoding

public String getEncoding()
Get the encoding used by this StringResource.
Returns:
the encoding name.

getInputStream

public InputStream getInputStream()
            throws IOException
Get an InputStream for the Resource.
Overrides:
getInputStream in interface Resource
Returns:
an InputStream containing this Resource's content.

getName

public String getName()
Synchronize access.
Overrides:
getName in interface Resource
Returns:
the name/value of this StringResource.

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 (for compatibility with java.io.File), or UNKNOWN_SIZE if not known.

getValue

public String getValue()
Get the value of this StringResource, resolving to the root reference if needed.
Returns:
the represented String.

hashCode

public int hashCode()
Get the hash code for this Resource.
Overrides:
hashCode in interface Resource
Returns:
hash code as int.

isExists

public boolean isExists()
The exists attribute tells whether a resource exists.
Overrides:
isExists in interface Resource
Returns:
true if this resource exists.

setEncoding

public void setEncoding(String s)
Set the encoding to be used for this StringResource.
Parameters:
s - the encoding name.

setName

public void setName(String s)
Enforce String immutability.
Overrides:
setName in interface Resource
Parameters:
s - the new name/value for this StringResource.

setRefid

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

setValue

public void setValue(String s)
The value attribute is a semantically superior alias for the name attribute.
Parameters:
s - the String's value.

toString

public String toString()
Overrides:
toString in interface Resource
Returns:
the string contents of the resource.
Since:
Ant 1.7