org.apache.tools.ant.types.resources

Class ContentTransformingResource

public abstract class ContentTransformingResource extends ResourceDecorator

A resource that transforms the content of another 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

Constructor Summary
protected ContentTransformingResource()
no arg constructor
protected ContentTransformingResource(ResourceCollection other)
Constructor with another resource to wrap.
Method Summary
Objectas(Class clazz)
Suppress FileProvider, re-implement Appendable
InputStreamgetInputStream()
Get an InputStream for the Resource.
OutputStreamgetOutputStream()
Get an OutputStream for the Resource.
longgetSize()
Get the size of this Resource.
protected booleanisAppendSupported()
Learn whether the transformation performed allows appends.
protected abstract InputStreamwrapStream(InputStream in)
Get a content-filtering/transforming InputStream.
protected abstract OutputStreamwrapStream(OutputStream out)
Get a content-filtering/transforming OutputStream.

Constructor Detail

ContentTransformingResource

protected ContentTransformingResource()
no arg constructor

ContentTransformingResource

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

Parameters: other the resource to wrap.

Method Detail

as

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

getInputStream

public InputStream getInputStream()
Get an InputStream for the Resource.

Returns: an InputStream containing this Resource's content.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if InputStreams are not supported for this Resource type.

getOutputStream

public OutputStream getOutputStream()
Get an OutputStream for the Resource.

Returns: an OutputStream to which content can be written.

Throws: IOException if unable to provide the content of this Resource as a stream. UnsupportedOperationException if OutputStreams are not supported for this Resource type.

getSize

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

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.

isAppendSupported

protected boolean isAppendSupported()
Learn 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 InputStream wrapStream(InputStream in)
Get a content-filtering/transforming InputStream.

Parameters: in InputStream to wrap, will never be null.

Returns: a compressed inputstream.

Throws: IOException if there is a problem.

wrapStream

protected abstract OutputStream wrapStream(OutputStream out)
Get a content-filtering/transforming OutputStream.

Parameters: out OutputStream to wrap, will never be null.

Returns: a compressed outputstream.

Throws: IOException if there is a problem.