Class DirectoryResourceFinder


public class DirectoryResourceFinder extends FileResourceFinder
A FileResourceFinder that finds file resources in a directory. The name of the file is constructed by concatenating a dirctory name with the resource name such that slashes in the resource name map to file separators.
  • Field Details

    • directory

      private final File directory
    • subdirectoryNameToFiles

      private final Map<String,Set<File>> subdirectoryNameToFiles
      Keys don't have trailing file separators (like "dir\"). The "root directory" is designated by key null. A null value indicates that the directory does not exist.
  • Constructor Details

    • DirectoryResourceFinder

      public DirectoryResourceFinder(File directory)
      Parameters:
      directory - the directory to use as the search base
  • Method Details

    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • findResourceAsFile

      @Nullable protected final File findResourceAsFile(String resourceName)
      Description copied from class: FileResourceFinder
      Converts a given resource resource name into a File.
      Specified by:
      findResourceAsFile in class FileResourceFinder
    • listFiles

      @Nullable private Set<File> listFiles(@Nullable String subdirectoryName)
      Parameters:
      subdirectoryName - E.g "java/lang", or "java\lang", or null
      Returns:
      null iff that subdirectory does not exist
    • list

      @Nullable public Iterable<Resource> list(String resourceNamePrefix, boolean recurse)
      Description copied from class: ListableResourceFinder
      Returns all resources who's names start with a given string. Only resources with a content are included, no "special entries" of any kind, e.g. directories.

      If the prefix string ends with "/", you will get a proper directory listing (recurse=false) or directory tree (recurse=true). Example:

         resourceFinder.list("dir/", true) =>
           dir/
           dir/afile
           dir/bfile
           dir/adir/
           dir/adir/file
           dir/bdir/
           dir/bdir/file
       

      Otherwise, you will get a strange subset of a directory listing, resp. directory tree, as follows:

         resourceFinder.list("dir/a", true) =>
           dir/afile
           dir/adir/
           dir/adir/file
       
      Specified by:
      list in class ListableResourceFinder
      Parameters:
      resourceNamePrefix - E.g. "" or "java/lang/"
      Returns:
      All resources who's name starts with the given prefix; null iff a location designated by the resourceNamePrefix does not exist