de.unkrig.commons.file.contentstransformation
Class SelectiveContentsTransformer

java.lang.Object
  extended by de.unkrig.commons.file.contentstransformation.SelectiveContentsTransformer
All Implemented Interfaces:
ContentsTransformer

public class SelectiveContentsTransformer
extends java.lang.Object
implements ContentsTransformer

A ContentsTransformer that delegates contents transformation to one of two delegates, depending on whether the name argument matches a string Predicate or not.


Constructor Summary
SelectiveContentsTransformer(Predicate<java.lang.String> namePredicate, ContentsTransformer transformer, ContentsTransformer delegate)
          If the namePredicate does not match the node's name, then the delegate is called.
 
Method Summary
 java.lang.String toString()
           
 void transform(java.lang.String name, java.io.InputStream is, java.io.OutputStream os)
          If the namePredicate does not match the name, then the delegate is called with arguments is and os.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelectiveContentsTransformer

public SelectiveContentsTransformer(Predicate<java.lang.String> namePredicate,
                                    ContentsTransformer transformer,
                                    ContentsTransformer delegate)
If the namePredicate does not match the node's name, then the delegate is called. Otherwise the delegate is called, and its output is piped through the transformer.

Notice that the preformance is particularly good if the transformer and/or the delegate is ContentsTransformations.COPY.

Method Detail

transform

public void transform(java.lang.String name,
                      java.io.InputStream is,
                      java.io.OutputStream os)
               throws java.io.IOException
If the namePredicate does not match the name, then the delegate is called with arguments is and os. Otherwise the delegate is called with argument is, and its output is piped through the transformer before it is written to os.

Specified by:
transform in interface ContentsTransformer
Parameters:
name - Desisgnates the contents that is transformed
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object