@Override protected PropertyResource getCheckedRef() { return (PropertyResource) super.getCheckedRef(); } }
@Override protected ArchiveResource getCheckedRef() { return (ArchiveResource) super.getCheckedRef(); } }
@Override protected FileResource getCheckedRef() { return (FileResource) super.getCheckedRef(); } }
@Override protected StringResource getCheckedRef() { return (StringResource) super.getCheckedRef(); }
/** * Fulfill the ResourceCollection contract. * @return an Iterator of Resources. * @since Ant 1.7 */ @Override public Iterator<Resource> iterator() { return isReference() ? getCheckedRef().iterator() : Collections.singleton(this).iterator(); }
/** * 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. * @since Ant 1.7 */ public InputStream getInputStream() throws IOException { if (isReference()) { return getCheckedRef().getInputStream(); } throw new UnsupportedOperationException(); }
/** * The exists attribute tells whether a resource exists. * @return true if this resource exists. */ public boolean isExists() { if (isReference()) { return getCheckedRef().isExists(); } //default true: return exists == null || exists; }
/** * Fulfill the ResourceCollection contract. * @return the size of this ResourceCollection. * @since Ant 1.7 */ @Override public int size() { return isReference() ? getCheckedRef().size() : 1; }
/** * 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. * @since Ant 1.7 */ public OutputStream getOutputStream() throws IOException { if (isReference()) { return getCheckedRef().getOutputStream(); } throw new UnsupportedOperationException(); }
/** * Tells if the resource is a directory. * @return boolean flag indicating if the resource is a directory. */ public boolean isDirectory() { if (isReference()) { return getCheckedRef().isDirectory(); } //default false: return directory != null && directory; }
/** * Implement basic Resource equality. * @param other the object to check against. * @return true if the specified Object is equal to this Resource. * @since Ant 1.7 */ @Override public boolean equals(Object other) { if (this == other) { return true; } if (isReference()) { return getCheckedRef().equals(other); } return other != null && other.getClass().equals(getClass()) && compareTo((Resource) other) == 0; }
/** * 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. * * <p>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.</p> * * <p>"/" will be used as the directory separator.</p> * @return the name of this resource. */ public String getName() { return isReference() ? getCheckedRef().getName() : name; }
/** * Get the hash code for this Resource. * @return hash code as int. * @since Ant 1.7 */ @Override public int hashCode() { if (isReference()) { return getCheckedRef().hashCode(); } String name = getName(); return MAGIC * (name == null ? NULL_NAME : name.hashCode()); }
/** * Fulfill the ResourceCollection contract. * @return whether this Resource is a FileProvider. * @since Ant 1.7 */ @Override public boolean isFilesystemOnly() { return (isReference() && getCheckedRef().isFilesystemOnly()) || this.as(FileProvider.class) != null; }
/** * Get the string representation of this Resource. * @return this Resource formatted as a String. * @since Ant 1.7 */ @Override public String toString() { if (isReference()) { return getCheckedRef().toString(); } String n = getName(); return n == null ? "(anonymous)" : n; }
/** * 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. * @since Ant 1.6.3 */ public long getSize() { if (isReference()) { return getCheckedRef().getSize(); } return isExists() ? (size != null ? size : UNKNOWN_SIZE) : 0L; }
/** * Delegates to a comparison of names. * @param other the object to compare to. * @return a negative integer, zero, or a positive integer as this Resource * is less than, equal to, or greater than the specified Resource. * @since Ant 1.6 */ @Override public int compareTo(Resource other) { if (isReference()) { return getCheckedRef().compareTo(other); } return toString().compareTo(other.toString()); }
/** * Tells the modification time in milliseconds since 01.01.1970 (the "epoch"). * * @return 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 {@link java.io.File#lastModified}; * or 0 if the notion of modification time is meaningless for this class * of resource (e.g. an inline string) */ public long getLastModified() { if (isReference()) { return getCheckedRef().getLastModified(); } if (!isExists() || lastmodified == null) { return UNKNOWN_DATETIME; } long result = lastmodified; return result < UNKNOWN_DATETIME ? UNKNOWN_DATETIME : result; }
/** * Get a long String representation of this Resource. * This typically should be the value of <code>toString()</code> * prefixed by a type description. * @return this Resource formatted as a long String. * @since Ant 1.7 */ public final String toLongString() { return isReference() ? getCheckedRef().toLongString() : getDataTypeName() + " \"" + toString() + '"'; }