Class SortFilter

java.lang.Object
All Implemented Interfaces:
Closeable, AutoCloseable, Readable, ChainableReader, Parameterizable

public final class SortFilter extends BaseParamFilterReader implements ChainableReader

Sort a file before and/or after the file.

Examples:

   <copy todir="build">
       <fileset dir="input" includes="*.txt"/>
       <filterchain>
           <sortfilter/>
       </filterchain>
   </copy>
 

Sort all files *.txt from src location and copy them into build location. The lines of each file are sorted in ascendant order comparing the lines via the String.compareTo(Object o) method.

   <copy todir="build">
       <fileset dir="input" includes="*.txt"/>
       <filterchain>
           <sortfilter reverse="true"/>
       </filterchain>
   </copy>
 

Sort all files *.txt from src location into reverse order and copy them into build location. If reverse parameter has value true (default value), then the output line of the files will be in ascendant order.

   <copy todir="build">
       <fileset dir="input" includes="*.txt"/>
       <filterchain>
           <filterreader classname="org.apache.tools.ant.filters.SortFilter">
             <param name="comparator" value="org.apache.tools.ant.filters.EvenFirstCmp"/>
           </filterreader>
       </filterchain>
   </copy>
 

Sort all files *.txt from src location using as sorting criterion EvenFirstCmp class, that sorts the file lines putting even lines first then odd lines for example. The modified files are copied into build location. The EvenFirstCmp, has to an instantiable class via Class.newInstance(), therefore in case of inner class has to be static. It also has to implement java.util.Comparator interface, for example:

         package org.apache.tools.ant.filters;
         ...(omitted)
           public final class EvenFirstCmp implements <b>Comparator</b> {
             public int compare(Object o1, Object o2) {
             ...(omitted)
             }
           }
 

The example above is equivalent to:

   <componentdef name="evenfirst"
                 classname="org.apache.tools.ant.filters.EvenFirstCmp"/>
   <copy todir="build">
       <fileset dir="input" includes="*.txt"/>
       <filterchain>
           <sortfilter>
               <evenfirst/>
           </sortfilter>
       </filterchain>
   </copy>
 

If parameter comparator is present, then reverse parameter will not be taken into account.

Since:
Ant 1.8.0