org.apache.tools.ant.types.resources

Class StringResource

public class StringResource extends Resource

Exposes a string as a Resource.

Since: Ant 1.7

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
voidaddText(String text)
Add nested text to this resource.
protected StringgetContent()
Get the content of this StringResource.
StringgetEncoding()
Get the encoding used by this StringResource.
InputStreamgetInputStream()
Get an InputStream for the Resource.
StringgetName()
Synchronize access.
OutputStreamgetOutputStream()
Get an OutputStream for the Resource.
longgetSize()
Get the size of this Resource.
StringgetValue()
Get the value of this StringResource, resolving to the root reference if needed.
inthashCode()
Get the hash code for this Resource.
booleanisExists()
The exists attribute tells whether a resource exists.
voidsetEncoding(String s)
Set the encoding to be used for this StringResource.
voidsetName(String s)
Enforce String immutability.
voidsetRefid(Reference r)
Overrides the super version.
voidsetValue(String s)
The value attribute is a semantically superior alias for the name attribute.
StringtoString()
Get the string.

Constructor Detail

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 Detail

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()
Get the content of this StringResource. See getValue

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()
Get an InputStream for the Resource.

Returns: an InputStream containing this Resource's content.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if InputStreams are not supported for this Resource type.

getName

public String getName()
Synchronize access.

Returns: the name/value of this StringResource.

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.

getSize

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

Returns: hash code as int.

isExists

public boolean isExists()
The exists attribute tells whether a resource exists.

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.

Parameters: s the new name/value for this StringResource.

setRefid

public void setRefid(Reference r)
Overrides the super version.

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()
Get the string. See getContent

Returns: the string contents of the resource.

Since: Ant 1.7