Class RegexFileFilter

  • All Implemented Interfaces:
    java.io.Serializable, FileFilter

    public class RegexFileFilter
    extends java.lang.Object
    implements FileFilter, java.io.Serializable
    Filters files using supplied regular expression(s).

    See java.util.regex.Pattern for regex matching rules.

    For example, to retrieve and print all java files where the name matched the regular expression in the current directory:

     FileSystemManager fsManager = VFS.getManager();
     FileObject dir = fsManager.toFileObject(new File("."));
     FileObject[] files = dir.findFiles(new FileFilterSelector(new RegexFileFilter("ˆ.*[tT]est(-\\d+)?\\.java$")));
     for (int i = 0; i < files.length; i++) {
         System.out.println(files[i]);
     }
     
    Since:
    2.4
    See Also:
    "http://commons.apache.org/proper/commons-io/", Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.regex.Pattern pattern
      The regular expression pattern that will be used to match file names.
      static java.lang.String PATTERN_IS_MISSING
      Exception message when no pattern is given in the constructor.
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      RegexFileFilter​(java.lang.String pattern)
      Construct a new regular expression filter.
      RegexFileFilter​(java.lang.String pattern, int flags)
      Construct a new regular expression filter with the specified flags.
      RegexFileFilter​(java.lang.String pattern, IOCase caseSensitivity)
      Construct a new regular expression filter with the specified flags case sensitivity.
      RegexFileFilter​(java.util.regex.Pattern pattern)
      Construct a new regular expression filter for a compiled regular expression.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(FileSelectInfo fileSelectInfo)
      Checks to see if the file name matches one of the regular expressions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PATTERN_IS_MISSING

        public static final java.lang.String PATTERN_IS_MISSING
        Exception message when no pattern is given in the constructor.
        See Also:
        Constant Field Values
      • pattern

        private final java.util.regex.Pattern pattern
        The regular expression pattern that will be used to match file names.
    • Constructor Detail

      • RegexFileFilter

        public RegexFileFilter​(java.util.regex.Pattern pattern)
        Construct a new regular expression filter for a compiled regular expression.
        Parameters:
        pattern - regular expression to match - Cannot be null
      • RegexFileFilter

        public RegexFileFilter​(java.lang.String pattern)
        Construct a new regular expression filter.
        Parameters:
        pattern - regular string expression to match - Cannot be null
      • RegexFileFilter

        public RegexFileFilter​(java.lang.String pattern,
                               int flags)
        Construct a new regular expression filter with the specified flags.
        Parameters:
        pattern - regular string expression to match
        flags - pattern flags - e.g. Pattern.CASE_INSENSITIVE
      • RegexFileFilter

        public RegexFileFilter​(java.lang.String pattern,
                               IOCase caseSensitivity)
        Construct a new regular expression filter with the specified flags case sensitivity.
        Parameters:
        pattern - regular string expression to match - Cannot be null
        caseSensitivity - how to handle case sensitivity, null means case-sensitive
    • Method Detail

      • accept

        public boolean accept​(FileSelectInfo fileSelectInfo)
        Checks to see if the file name matches one of the regular expressions.
        Specified by:
        accept in interface FileFilter
        Parameters:
        fileSelectInfo - the File to check
        Returns:
        true if the file matches one of the regular expressions