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

CompressedResource

public abstract class CompressedResource extends org.apache.tools.ant.types.Resource
A compressed resource.

Wraps around another resource, delegates all queries (except getSize) to that other resource but uncompresses/compresses streams on the fly.

since
Ant 1.7

Fields Summary
private org.apache.tools.ant.types.Resource
resource
Constructors Summary
public CompressedResource()
no arg constructor

    
public CompressedResource(org.apache.tools.ant.types.ResourceCollection other)
Constructor with another resource to wrap.

param
other the resource to wrap.

        addConfigured(other);
    
Methods Summary
public voidaddConfigured(org.apache.tools.ant.types.ResourceCollection a)
Sets the resource to wrap using a single-element collection.

param
a the resource to wrap as a single element Resource collection.

        checkChildrenAllowed();
        if (resource != null) {
            throw new BuildException("you must not specify more than one"
                                     + " resource");
        }
        if (a.size() != 1) {
            throw new BuildException("only single argument resource collections"
                                     + " are supported");
        }
        resource = (Resource) a.iterator().next();
    
public intcompareTo(java.lang.Object other)
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.

        if (other == this) {
            return 0;
        }
        if (other instanceof CompressedResource) {
            return getResource().compareTo(
                ((CompressedResource) other).getResource());
        }
        return getResource().compareTo(other);
    
protected abstract java.lang.StringgetCompressionName()

return
the name of the compression method.

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.

        InputStream in = getResource().getInputStream();
        if (in != null) {
            in = wrapStream(in);
        }
        return in;
    
public longgetLastModified()
Tells the modification time in milliseconds since 01.01.1970 .

return
0 if the resource does not exist to mirror the behavior of {@link java.io.File File}.

        return getResource().getLastModified();
    
public java.lang.StringgetName()
Get the name of the resource.

return
the name of the wrapped resource.

        return getResource().getName();
    
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.

        OutputStream out = getResource().getOutputStream();
        if (out != null) {
            out = wrapStream(out);
        }
        return out;
    
private org.apache.tools.ant.types.ResourcegetResource()

        if (isReference()) {
            return (Resource) getCheckedRef();
        } else if (resource == null) {
            throw new BuildException("no resource specified");
        }
        return resource;
    
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 (isExists()) {
            InputStream in = null;
            try {
                in = getInputStream();
                byte[] buf = new byte[8192];
                int size = 0;
                int readNow;
                while ((readNow = in.read(buf, 0, buf.length)) > 0) {
                    size += readNow;
                }
                return size;
            } catch (IOException ex) {
                throw new BuildException("caught exception while reading "
                                         + getName(), ex);
            } finally {
                FileUtils.close(in);
            }
        } else {
            return 0;
        }
    
public inthashCode()
Get the hash code for this Resource.

return
hash code as int.

        return getResource().hashCode();
    
public booleanisDirectory()
Tells if the resource is a directory.

return
boolean flag indicating if the resource is a directory.

        return getResource().isDirectory();
    
public booleanisExists()
The exists attribute tells whether a file exists.

return
true if this resource exists.

        return getResource().isExists();
    
public booleanisFilesystemOnly()
Fulfill the ResourceCollection contract.

return
whether this Resource is a FileResource.

        return false;
    
public voidsetDirectory(boolean directory)
Override setDirectory.

param
directory not used.
throws
BuildException always.

        throw new BuildException("you can't change the directory state of a "
                                 + " compressed resource");
    
public voidsetExists(boolean exists)
Set the exists attribute.

param
exists if true, this resource exists.

        throw new BuildException("you can't change the exists state of a "
                                 + " compressed resource");
    
public voidsetLastModified(long lastmodified)
Override setLastModified.

param
lastmodified not used.
throws
BuildException always.

        throw new BuildException("you can't change the timestamp of a "
                                 + " compressed resource");
    
public voidsetName(java.lang.String name)
Overridden, not allowed to set the name of the resource.

param
name not used.
throws
BuildException always.

        throw new BuildException("you can't change the name of a compressed"
                                 + " resource");
    
public voidsetRefid(org.apache.tools.ant.types.Reference r)
Overrides the base version.

param
r the Reference to set.

        if (resource != null) {
            throw noChildrenAllowed();
        }
        super.setRefid(r);
    
public voidsetSize(long size)
Override setSize.

param
size not used.
throws
BuildException always.

        throw new BuildException("you can't change the size of a "
                                 + " compressed resource");
    
public java.lang.StringtoString()
Get the string representation of this Resource.

return
this Resource formatted as a String.
since
Ant 1.7

        return getCompressionName() + " compressed "
            + getResource().toString();
    
protected abstract java.io.InputStreamwrapStream(java.io.InputStream in)
Is supposed to wrap the stream to allow decompression on the fly.

param
in InputStream to wrap, will never be null.
return
a compressed inputstream.
throws
IOException if there is a problem.

protected abstract java.io.OutputStreamwrapStream(java.io.OutputStream out)
Is supposed to wrap the stream to allow compression on the fly.

param
out OutputStream to wrap, will never be null.
return
a compressed outputstream.
throws
IOException if there is a problem.