org.apache.tools.ant.types.resources
Class ContentTransformingResource

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.types.DataType
          extended by org.apache.tools.ant.types.Resource
              extended by org.apache.tools.ant.types.resources.ResourceDecorator
                  extended by org.apache.tools.ant.types.resources.ContentTransformingResource
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, ResourceCollection
Direct Known Subclasses:
CompressedResource

public abstract class ContentTransformingResource
extends ResourceDecorator

A compressed resource.

Wraps around another resource, delegates all queries (except getSize) to that other resource but transforms stream content on the fly.

Since:
Ant 1.8

Field Summary
 
Fields inherited from class org.apache.tools.ant.types.Resource
MAGIC, UNKNOWN_DATETIME, UNKNOWN_SIZE
 
Fields inherited from class org.apache.tools.ant.types.DataType
checked, ref
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
ContentTransformingResource()
          no arg constructor
ContentTransformingResource(ResourceCollection other)
          Constructor with another resource to wrap.
 
Method Summary
 java.lang.Object as(java.lang.Class clazz)
          Suppress FileProvider, re-implement Appendable
 java.io.InputStream getInputStream()
          Get an InputStream for the Resource.
 java.io.OutputStream getOutputStream()
          Get an OutputStream for the Resource.
 long getSize()
          Get the size of this Resource.
protected  boolean isAppendSupported()
          whether the transformation performed allows appends.
protected abstract  java.io.InputStream wrapStream(java.io.InputStream in)
          Is supposed to wrap the stream.
protected abstract  java.io.OutputStream wrapStream(java.io.OutputStream out)
          Is supposed to wrap the stream to allow transformation on the fly.
 
Methods inherited from class org.apache.tools.ant.types.resources.ResourceDecorator
addConfigured, compareTo, dieOnCircularReference, getLastModified, getName, getResource, hashCode, isDirectory, isExists, isFilesystemOnly, setDirectory, setExists, setLastModified, setName, setRefid, setSize
 
Methods inherited from class org.apache.tools.ant.types.Resource
clone, equals, getMagicNumber, iterator, size, toLongString, toString
 
Methods inherited from class org.apache.tools.ant.types.DataType
checkAttributesAllowed, checkChildrenAllowed, circularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContentTransformingResource

public ContentTransformingResource()
no arg constructor


ContentTransformingResource

public ContentTransformingResource(ResourceCollection other)
Constructor with another resource to wrap.

Parameters:
other - the resource to wrap.
Method Detail

getSize

public long getSize()
Get the size of this Resource.

Overrides:
getSize in class ResourceDecorator
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.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get an InputStream for the Resource.

Overrides:
getInputStream in class ResourceDecorator
Returns:
an InputStream containing this Resource's content.
Throws:
java.io.IOException - if unable to provide the content of this Resource as a stream.
java.lang.UnsupportedOperationException - if InputStreams are not supported for this Resource type.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Get an OutputStream for the Resource.

Overrides:
getOutputStream in class ResourceDecorator
Returns:
an OutputStream to which content can be written.
Throws:
java.io.IOException - if unable to provide the content of this Resource as a stream.
java.lang.UnsupportedOperationException - if OutputStreams are not supported for this Resource type.

as

public java.lang.Object as(java.lang.Class clazz)
Suppress FileProvider, re-implement Appendable

Overrides:
as in class ResourceDecorator

isAppendSupported

protected boolean isAppendSupported()
whether the transformation performed allows appends.

In general compressed outputs will become invalid if they are appended to, for example.

This implementations returns false.


wrapStream

protected abstract java.io.InputStream wrapStream(java.io.InputStream in)
                                           throws java.io.IOException
Is supposed to wrap the stream.

Parameters:
in - InputStream to wrap, will never be null.
Returns:
a compressed inputstream.
Throws:
java.io.IOException - if there is a problem.

wrapStream

protected abstract java.io.OutputStream wrapStream(java.io.OutputStream out)
                                            throws java.io.IOException
Is supposed to wrap the stream to allow transformation on the fly.

Parameters:
out - OutputStream to wrap, will never be null.
Returns:
a compressed outputstream.
Throws:
java.io.IOException - if there is a problem.