FileDocCategorySizeDatePackage
StringResource.javaAPI DocApache Ant 1.706521Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.types.resources

StringResource

public class StringResource extends org.apache.tools.ant.types.Resource
Exposes a string as a Resource.
since
Ant 1.7

Fields Summary
private static final int
STRING_MAGIC
Magic number
private String
encoding
Constructors Summary
public StringResource()
Default constructor.


           
      
    
public StringResource(String value)
Construct a StringResource with the supplied value.

param
value the value of this StringResource.

        setValue(value);
    
Methods Summary
protected synchronized java.lang.StringgetContent()
Get the content of this StringResource.

return
a String; if the Project has been set properties replacement will be attempted.

        if (isReference()) {
            return ((StringResource) getCheckedRef()).getContent();
        }
        String value = getValue();
        if (value == null) {
            return value;
        }
        return getProject() == null
            ? value : getProject().replaceProperties(value);
    
public synchronized java.lang.StringgetEncoding()
Get the encoding used by this StringResource.

return
the encoding name.

        return encoding;
    
public synchronized java.io.InputStreamgetInputStream()
Get an InputStream for the Resource.

return
an InputStream containing this Resource's content.
throws
IOException if unable to provide the content of this Resource as a stream.
throws
UnsupportedOperationException if InputStreams are not supported for this Resource type.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getInputStream();
        }
        //I can't get my head around this; is encoding treatment needed here?
        return
            //new oata.util.ReaderInputStream(new InputStreamReader(
            new ByteArrayInputStream(getContent().getBytes());
            //, encoding), encoding);
    
public synchronized java.lang.StringgetName()
Synchronize access.

return
the name/value of this StringResource.

        return super.getName();
    
public synchronized java.io.OutputStreamgetOutputStream()
Get an OutputStream for the Resource.

return
an OutputStream to which content can be written.
throws
IOException if unable to provide the content of this Resource as a stream.
throws
UnsupportedOperationException if OutputStreams are not supported for this Resource type.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getOutputStream();
        }
        if (getValue() != null) {
            throw new ImmutableResourceException();
        }
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        return new FilterOutputStream(baos) {
            public void close() throws IOException {
                super.close();
                StringResource.this.setValue(encoding == null
                    ? baos.toString() : baos.toString(encoding));
            }
        };
    
public synchronized longgetSize()
Get the size of this Resource.

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

        return isReference()
            ? ((Resource) getCheckedRef()).getSize()
            : (long) getContent().length();
    
public synchronized java.lang.StringgetValue()
Get the value of this StringResource.

return
the represented String.

        return getName();
    
public synchronized inthashCode()
Get the hash code for this Resource.

return
hash code as int.

        if (isReference()) {
            return getCheckedRef().hashCode();
        }
        return super.hashCode() * STRING_MAGIC;
    
public synchronized voidsetEncoding(java.lang.String s)
Set the encoding to be used for this StringResource.

param
s the encoding name.

        encoding = s;
    
public synchronized voidsetName(java.lang.String s)
Enforce String immutability.

param
s the new name/value for this StringResource.

        if (getName() != null) {
            throw new BuildException(new ImmutableResourceException());
        }
        super.setName(s);
    
public voidsetRefid(org.apache.tools.ant.types.Reference r)
Overrides the super version.

param
r the Reference to set.

        if (encoding != null) {
            throw tooManyAttributes();
        }
        super.setRefid(r);
    
public synchronized voidsetValue(java.lang.String s)
The value attribute is a semantically superior alias for the name attribute.

param
s the String's value.

        setName(s);
    
public java.lang.StringtoString()
Get the string.

return
the string contents of the resource.
since
Ant 1.7

        if (isReference()) {
            return getCheckedRef().toString();
        }
        return String.valueOf(getContent());