Class PrefixFileFilter

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

    public class PrefixFileFilter
    extends java.lang.Object
    implements FileFilter, java.io.Serializable
    Filters file names for a certain prefix.

    For example, to print all files and directories in the current directory whose name starts with a .:

     FileSystemManager fsManager = VFS.getManager();
     FileObject dir = fsManager.toFileObject(new File("."));
     FileObject[] files = dir.findFiles(new FileFilterSelector(new PrefixFileFilter(".")));
     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 IOCase caseSensitivity
      Whether the comparison is case sensitive.
      private java.util.List<java.lang.String> prefixes
      The file name prefixes to search for.
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      PrefixFileFilter​(java.lang.String... prefixes)
      Constructs a new Prefix file filter for any of an array of prefixes.
      PrefixFileFilter​(java.util.List<java.lang.String> prefixes)
      Constructs a new Prefix file filter for a list of prefixes.
      PrefixFileFilter​(IOCase caseSensitivity, java.lang.String... prefixes)
      Constructs a new Prefix file filter for any of an array of prefixes specifying case-sensitivity.
      PrefixFileFilter​(IOCase caseSensitivity, java.util.List<java.lang.String> prefixes)
      Constructs a new Prefix file filter for a list of prefixes specifying case-sensitivity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(FileSelectInfo fileSelectInfo)
      Checks to see if the file name starts with the prefix.
      java.lang.String toString()
      Provide a String representation of this file filter.
      • Methods inherited from class java.lang.Object

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

      • caseSensitivity

        private final IOCase caseSensitivity
        Whether the comparison is case sensitive.
      • prefixes

        private final java.util.List<java.lang.String> prefixes
        The file name prefixes to search for.
    • Constructor Detail

      • PrefixFileFilter

        public PrefixFileFilter​(java.util.List<java.lang.String> prefixes)
        Constructs a new Prefix file filter for a list of prefixes.
        Parameters:
        prefixes - the prefixes to allow, must not be null
      • PrefixFileFilter

        public PrefixFileFilter​(IOCase caseSensitivity,
                                java.util.List<java.lang.String> prefixes)
        Constructs a new Prefix file filter for a list of prefixes specifying case-sensitivity.
        Parameters:
        caseSensitivity - how to handle case sensitivity, null means case-sensitive
        prefixes - the prefixes to allow, must not be null
      • PrefixFileFilter

        public PrefixFileFilter​(java.lang.String... prefixes)
        Constructs a new Prefix file filter for any of an array of prefixes.

        The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.

        Parameters:
        prefixes - the prefixes to allow, must not be null
      • PrefixFileFilter

        public PrefixFileFilter​(IOCase caseSensitivity,
                                java.lang.String... prefixes)
        Constructs a new Prefix file filter for any of an array of prefixes specifying case-sensitivity.
        Parameters:
        prefixes - the prefixes to allow, must not 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 starts with the prefix.
        Specified by:
        accept in interface FileFilter
        Parameters:
        fileSelectInfo - the File to check
        Returns:
        true if the file name starts with one of our prefixes
      • toString

        public java.lang.String toString()
        Provide a String representation of this file filter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation