Top Description Fields Constructors Methods
org.codehaus.commons.compiler.util.resource

public Class DirectoryResourceFinder

extends FileResourceFinder
Class Inheritance
Imports
java.io.File, java.util.ArrayList, .HashMap, .HashSet, .List, .Map, .Set, org.codehaus.commons.nullanalysis.Nullable

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 Summary

Modifier and TypeField and Description
private final File
private final Map<String, Set<File>>
subdirectoryNameToFiles

Keys don't have trailing file separators (like "dir\").

Constructor Summary

AccessConstructor and Description
public
DirectoryResourceFinder(File
the directory to use as the search base
directory
)

Method Summary

Modifier and TypeMethod and Description
protected final File
findResourceAsFile(String resourceName)

Implements abstract org.codehaus.commons.compiler.util.resource.FileResourceFinder.findResourceAsFile.

Converts a given resource resource name into a File.
public Iterable<Resource>
list(String
E.g. "" or "java/lang/"
resourceNamePrefix
,
boolean recurse)

Implements abstract org.codehaus.commons.compiler.util.resource.ListableResourceFinder.list.

Returns all resources who's names start with a given string.
private Set<File>

Returns:

null iff that subdirectory does not exist
listFiles
(String
E.g "java/lang", or "java\lang", or null
subdirectoryName
)

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.codehaus.commons.compiler.util.resource.FileResourceFinder:
findResource

Field Detail

directoryback to summary
private final File directory
subdirectoryNameToFilesback to summary
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 Detail

DirectoryResourceFinderback to summary
public DirectoryResourceFinder(File directory)
Parameters
directory:File

the directory to use as the search base

Method Detail

findResourceAsFileback to summary
protected final File findResourceAsFile(String resourceName)

Implements abstract org.codehaus.commons.compiler.util.resource.FileResourceFinder.findResourceAsFile.

Doc from org.codehaus.commons.compiler.util.resource.FileResourceFinder.findResourceAsFile.

Converts a given resource resource name into a File.

Annotations
@Override
@Nullable
listback to summary
public Iterable<Resource> list(String resourceNamePrefix, boolean recurse)

Implements abstract org.codehaus.commons.compiler.util.resource.ListableResourceFinder.list.

Doc from org.codehaus.commons.compiler.util.resource.ListableResourceFinder.list.

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
Parameters
resourceNamePrefix:String

E.g. "" or "java/lang/"

Returns:Iterable<Resource>

All resources who's name starts with the given prefix; null iff a location designated by the resourceNamePrefix does not exist

Annotations
@Override
@Nullable
listFilesback to summary
private Set<File> listFiles(String subdirectoryName)
Parameters
subdirectoryName:String

E.g "java/lang", or "java\lang", or null

Returns:Set<File>

null iff that subdirectory does not exist

Annotations
@Nullable
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override