Class FilePathMatcher

Direct Known Subclasses:
MatchExtensions, MatchGlob, MatchRegularExpression

public abstract class FilePathMatcher extends AnchorBean<FilePathMatcher>
Matches file-paths against some kind of pattern.

Search operations can be executed against this pattern, to find all files in a directory that match.

Author:
Owen Feehan
  • Constructor Details

    • FilePathMatcher

      public FilePathMatcher()
  • Method Details

    • matchingFiles

      public List<File> matchingFiles(Path directory, boolean recursive) throws InputReadFailedException
      Like matchingFiles(Path, boolean, boolean, boolean, Optional, Optional) but uses sensible defaults.

      Hidden files are ignored.

      Continues even when a directory-access-error occurs, without throwing an exception.

      No maximum directory depth is imposed.

      No parameters are applied.

      Parameters:
      directory - root directory to search.
      recursive - whether to recursively search.
      Returns:
      a collection of files matching the conditions.
      Throws:
      InputReadFailedException - if an error occurrs reading/writing or interacting with the filesystem.
    • matchingFiles

      public List<File> matchingFiles(Path directory, boolean recursive, boolean ignoreHidden, boolean acceptDirectoryErrors, Optional<Integer> maxDirectoryDepth, Optional<InputManagerParameters> parameters) throws InputReadFailedException
      Finds a collection of files that match particular conditions on their paths.
      Parameters:
      directory - root directory to search.
      recursive - whether to recursively search.
      ignoreHidden - whether to ignore hidden files/directories or not.
      acceptDirectoryErrors - if true, continues when a directory-access-error occurs (logging it), otherwise throws an exception.
      maxDirectoryDepth - a maximum depth in directories to search.
      parameters - parameters providing input-context
      Returns:
      a collection of files matching the conditions.
      Throws:
      InputReadFailedException - if an error occurs reading/writing or interacting with the filesystem.
    • createMatcherFile

      protected abstract CheckedPredicate<Path,IOException> createMatcherFile(Path directory, Optional<InputContextParameters> inputContext) throws InputReadFailedException
      Create a predicate to be used for matching against path.
      Parameters:
      directory - the directory being searched. Only paths in this directory (or its subdirectories) will ever be passed to the predicate.
      inputContext - the input-context.
      Returns:
      a predicate that can be used to accept or reject a path (contained in directory.
      Throws:
      InputReadFailedException - if the testing of the predicate fails.
    • canMatchSubdirectories

      protected abstract boolean canMatchSubdirectories()
      Determines if it possible to match a file in a subdirectory.

      If it impossible to match a subdirectory, this allows us to disable any recursive search, as it is pointless effort.

      Returns:
      true if its possible for the predicate returned by createMatcherFile to match a file in a subdirectory, false otherwise.