Package mars.util
Class FilenameFinder
java.lang.Object
mars.util.FilenameFinder
Utility class to perform necessary file-related search
operations. One is to find file names in JAR file,
another is to find names of files in given directory
of normal file system.
- Version:
- October 2006
- Author:
- Pete Sanderson
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
fileExtensionMatch
(String name, String extension) Determine if given filename ends with given extension.findFilenames
(ClassLoader classLoader, String directoryPath, String fileExtension) Locate files and return list of file names.findFilenames
(ClassLoader classLoader, String directoryPath, List<String> fileExtensions) Locate files and return list of file names.findFilenames
(String directoryPath, String fileExtension) Locate files and return list of file names.findFilenames
(String directoryPath, List<String> fileExtensions) Locate files and return list of file names.findFilenames
(List<String> nameList, String fileExtension) Return list of file names.findFilenames
(List<String> nameList, List<String> fileExtensions) Return list of file names.static String
getExtension
(File file) Get the filename extension of the specified File.static FileFilter
getFileFilter
(String extension, String description) Get a FileFilter that will filter files based on the given filename extension.static FileFilter
getFileFilter
(String extension, String description, boolean acceptDirectories) Get a FileFilter that will filter files based on the given filename extension.static FileFilter
getFileFilter
(List<String> extensions, String description) Get a FileFilter that will filter files based on the given list of filename extensions.static FileFilter
getFileFilter
(List<String> extensions, String description, boolean acceptDirectories) Get a FileFilter that will filter files based on the given list of filename extensions.
-
Field Details
-
MATCH_ALL_EXTENSIONS
-
-
Constructor Details
-
FilenameFinder
public FilenameFinder()
-
-
Method Details
-
findFilenames
public static List<String> findFilenames(ClassLoader classLoader, String directoryPath, String fileExtension) Locate files and return list of file names. Given a known relative directory path, it will locate it and build list of all names of files in that directory having the given file extension. If the "known file path" doesn't work because MARS is running from an executable JAR file, it will locate the directory in the JAR file and proceed from there. NOTE: since this uses the class loader to get the resource, the directory path needs to be relative to classpath, not absolute. To work with an arbitrary file system, use the other version of this overloaded method. Will NOT match directories that happen to have the desired extension.- Parameters:
classLoader
- class loader to usedirectoryPath
- Search will be confined to this directory. Use "/" as separator but do NOT include starting or ending "/" (e.g. mars/tools)fileExtension
- Only files with this extension will be added to the list. Do NOT include the "." in extension.- Returns:
- array list of matching file names as Strings. If none, list is empty.
-
findFilenames
public static List<String> findFilenames(ClassLoader classLoader, String directoryPath, List<String> fileExtensions) Locate files and return list of file names. Given a known relative directory path, it will locate it and build list of all names of files in that directory having the given file extension. If the "known file path" doesn't work because MARS is running from an executable JAR file, it will locate the directory in the JAR file and proceed from there. NOTE: since this uses the class loader to get the resource, the directory path needs to be relative to classpath, not absolute. To work with an arbitrary file system, use the other version of this overloaded method.- Parameters:
classLoader
- class loader to usedirectoryPath
- Search will be confined to this directory. Use "/" as separator but do NOT include starting or ending "/" (e.g. mars/tools)fileExtensions
- ArrayList of Strings containing file extensions. Only files with an extension in this list will be added to the list. Do NOT include the ".", e.g. "class" not ".class". If Arraylist or extension null or empty, all files are added.- Returns:
- array list of matching file names as Strings. If none, list is empty.
-
findFilenames
Locate files and return list of file names. Given a known directory path, it will locate it and build list of all names of files in that directory having the given file extension. If file extension is null or empty, all filenames are returned. Returned list contains absolute filename paths.- Parameters:
directoryPath
- Search will be confined to this directory.fileExtension
- Only files with this extension will be added to the list. Do NOT include "." in extension. If null or empty string, all files are added.- Returns:
- ArrayList of matching file names (absolute path). If none, list is empty.
-
findFilenames
Locate files and return list of file names. Given a known directory path, it will locate it and build list of all names of files in that directory having the given file extension. If file extension is null or empty, all filenames are returned. Returned list contains absolute filename paths.- Parameters:
directoryPath
- Search will be confined to this directory.fileExtensions
- ArrayList of Strings containing file extensions. Only files with an extension in this list will be added to the list. Do NOT include the "." in extensions. If Arraylist or extension null or empty, all files are added.- Returns:
- ArrayList of matching file names (absolute path). If none, list is empty.
-
findFilenames
Return list of file names. Given a list of file names, it will return the list of all having the given file extension. If file extension is null or empty, all filenames are returned. Returned list contains absolute filename paths.- Parameters:
nameList
- ArrayList of String containing file names.fileExtension
- Only files with this extension will be added to the list. If null or empty string, all files are added. Do NOT include "." in extension.- Returns:
- ArrayList of matching file names (absolute path). If none, list is empty.
-
findFilenames
Return list of file names. Given a list of file names, it will return the list of all having the given file extension. If file extension is null or empty, all filenames are returned. Returned list contains absolute filename paths.- Parameters:
nameList
- ArrayList of String containing file names.fileExtensions
- ArrayList of Strings containing file extensions. Only files with an extension in this list will be added to the list. Do NOT include the "." in extensions. If Arraylist or extension null or empty, all files are added.- Returns:
- ArrayList of matching file names (absolute path). If none, list is empty.
-
getExtension
Get the filename extension of the specified File.- Parameters:
file
- the File object representing the file of interest.- Returns:
- The filename extension (everything that follows last '.' in filename) or null if none.
-
getFileFilter
public static FileFilter getFileFilter(List<String> extensions, String description, boolean acceptDirectories) Get a FileFilter that will filter files based on the given list of filename extensions.- Parameters:
extensions
- ArrayList of Strings, each string is acceptable filename extension.description
- String containing description to be added in parentheses after list of extensions.acceptDirectories
- boolean value true if directories are accepted by the filter, false otherwise.- Returns:
- a FileFilter object that accepts files with given extensions, and directories if so indicated.
-
getFileFilter
Get a FileFilter that will filter files based on the given list of filename extensions. All directories are accepted by the filter.- Parameters:
extensions
- ArrayList of Strings, each string is acceptable filename extensiondescription
- String containing description to be added in parentheses after list of extensions.- Returns:
- a FileFilter object that accepts files with given extensions, and directories if so indicated.
-
getFileFilter
public static FileFilter getFileFilter(String extension, String description, boolean acceptDirectories) Get a FileFilter that will filter files based on the given filename extension.- Parameters:
extension
- String containing acceptable filename extension.description
- String containing description to be added in parentheses after list of extensions.acceptDirectories
- boolean value true if directories are accepted by the filter, false otherwise.- Returns:
- a FileFilter object that accepts files with given extensions, and directories if so indicated.
-
getFileFilter
Get a FileFilter that will filter files based on the given filename extension. All directories are accepted by the filter.- Parameters:
extension
- String containing acceptable filename extensiondescription
- String containing description to be added in parentheses after list of extensions.- Returns:
- a FileFilter object that accepts files with given extensions, and directories if so indicated.
-
fileExtensionMatch
Determine if given filename ends with given extension.- Parameters:
name
- A String containing the file nameextension
- A String containing the file extension. Leading period is optional.- Returns:
- Returns true if filename ends with given extension, false otherwise.
-