FileDocCategorySizeDatePackage
PropertyResource.javaAPI DocApache Ant 1.704577Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types.resources

PropertyResource

public class PropertyResource extends org.apache.tools.ant.types.Resource
Exposes an Ant property as a Resource.
since
Ant 1.7

Fields Summary
private static final int
PROPERTY_MAGIC
Magic number
private static final InputStream
UNSET
Constructors Summary
public PropertyResource()
Default constructor.


           
      
    
public PropertyResource(org.apache.tools.ant.Project p, String n)
Construct a new PropertyResource with the specified name.

param
p the project to use.
param
n the String name of this PropertyResource (Ant property name/key).

        super(n);
        setProject(p);
    
Methods Summary
public 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();
        }
        return isExists() ? new ByteArrayInputStream(getValue().getBytes()) : UNSET;
    
public 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 (isExists()) {
            throw new ImmutableResourceException();
        }
        return new PropertyOutputStream(getProject(), getName());
    
public 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.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getSize();
        }
        return isExists() ? (long) getValue().length() : 0L;
    
public java.lang.StringgetValue()
Get the value of this PropertyResource.

return
the value of the specified Property.

        Project p = getProject();
        return p == null ? null : p.getProperty(getName());
    
public inthashCode()
Get the hash code for this Resource.

return
hash code as int.

        if (isReference()) {
            return getCheckedRef().hashCode();
        }
        return super.hashCode() * PROPERTY_MAGIC;
    
public booleanisExists()
Find out whether this Resource exists.

return
true if the Property is set, false otherwise.

        return getValue() != null;
    
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(getValue());