Class ContentTransformingResource

All Implemented Interfaces:
Cloneable, Comparable<Resource>, Iterable<Resource>, ResourceCollection
Direct Known Subclasses:
CompressedResource

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 Details

    • ContentTransformingResource

      protected ContentTransformingResource()
      no arg constructor
    • ContentTransformingResource

      protected ContentTransformingResource(ResourceCollection other)
      Constructor with another resource to wrap.
      Parameters:
      other - the resource to wrap.
  • Method Details

    • 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 InputStream getInputStream() throws IOException
      Get an InputStream for the Resource.
      Overrides:
      getInputStream in class ResourceDecorator
      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() throws IOException
      Get an OutputStream for the Resource.
      Overrides:
      getOutputStream in class ResourceDecorator
      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.
    • as

      public <T> T as(Class<T> clazz)
      Suppress FileProvider, re-implement Appendable
      Overrides:
      as in class ResourceDecorator
      Type Parameters:
      T - desired type
      Parameters:
      clazz - a class
      Returns:
      resource of a desired type
    • 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.

      Returns:
      boolean false
    • wrapStream

      protected abstract InputStream wrapStream(InputStream in) throws IOException
      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) throws IOException
      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.