info.informatica.io
Class WildcardFilter

java.lang.Object
  extended by info.informatica.io.WildcardFilter
All Implemented Interfaces:
FileFilter, FilenameFilter

public final 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).

Version:
2.00
Author:
amengual at informatica dot info

Constructor Summary
WildcardFilter()
          Default Constructor.
WildcardFilter(FilesystemInfo filesystemInfo)
          Constructor with FilesystemInfo argument.
 
Method Summary
 boolean accept(File pathname)
           
 boolean accept(File dir, String name)
           
 boolean accept(String path)
           
 String[] getAllDirs()
          Gives an array of all directories matching the wildcard path.
 String getCanonWildcardPath()
           
 FilePatternSpec getFilePatternSpec()
           
 String[] getFilterDirs(String path)
           
 String mergeWildcard(String path)
          Try to merge this path with wildcards.
 void setWildcardPath(String path)
          Set the wildcard path to be used.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

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:
list of all 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.