Package io.sf.jclf.io

Class WildcardFilter

java.lang.Object
io.sf.jclf.io.WildcardFilter
All Implemented Interfaces:
FileFilter, FilenameFilter

public class WildcardFilter extends Object implements FilenameFilter, FileFilter
Wildcard filter for use as a FilenameFilter or FileFilter.

Implements the file Filter-related interfaces, and allows to use wildcards as Filter specifications.

Note for Windows users: while Java allows compatibility with Unix-style paths of the type C:/path/to/file, this filter does not allow this and requires the typical DOS paths (C:\path\to\file).

  • Constructor Details

    • WildcardFilter

      public WildcardFilter()
      Default Constructor. Tries to guess the current filesystem properties as for a Unix/Windows system.
    • WildcardFilter

      public WildcardFilter(FilesystemInfo filesystemInfo)
      Constructor with FilesystemInfo argument.
      Parameters:
      filesystemInfo - the FilesystemInfo object appropriate for the filesystem.
  • Method Details

    • getFilePatternSpec

      public FilePatternSpec getFilePatternSpec()
    • setWildcardPath

      public void setWildcardPath(String path)
      Set the wildcard path to be used.
      Parameters:
      path - The path with wildcards.
    • getCanonWildcardPath

      public String getCanonWildcardPath()
      Returns:
      the wildcard path, qualified with disk label and disk separator if applicable
    • accept

      public boolean accept(File dir, String name)
      Specified by:
      accept in interface FilenameFilter
    • accept

      public boolean accept(File pathname)
      Specified by:
      accept in interface FileFilter
    • accept

      public boolean accept(String path)
    • getFilterDirs

      public String[] getFilterDirs(String path)
      Parameters:
      path - Absolute path with first-level wildcards.
      Returns:
      list of directories that match the wildcard path. Returns null if path is null, or if path parent is not a directory. Returns a zero-length array if no matching directories found.
    • getAllDirs

      public String[] getAllDirs()
      Gives an array of all directories matching the wildcard path.

      The reason to give directories (merged with file part of the wildcard path) is to lower memory consumption when using very generic wildcards, as for example it is not the same to return all the directories in a Filesystem than returning all the directories and all the files.

      Returns:
      array of all directories that match the full wildcard path, merged with the file part of the wildcard path, or null if none matches.
    • getAllMatchingDirectories

      public List<String> getAllMatchingDirectories()
      Gives the list of all directories matching the wildcard path.

      The reason to give directories (merged with file part of the wildcard path) is to lower memory consumption when using very generic wildcards, as for example it is not the same to return all the directories in a Filesystem than returning all the directories and all the files.

      Returns:
      list of all the directories that match the full wildcard path, merged with the file part of the wildcard path.
    • mergeWildcard

      public String mergeWildcard(String path)
      Try to merge this path with wildcards.

      If matches, return the merged path, otherwise null.

      Parameters:
      path - the path to merge.
      Returns:
      the merged path, or null if path does not match wildcard.