Package rs.baselib.io
Class FileFinder
java.lang.Object
rs.baselib.io.FileFinder
Utility to find a file on disk.
- Author:
- RalphSchuster
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic URL
Tries to find the file specified from filesystem or classpath.static URL
Tries to find the file or directory specified from filesystem or classpath.static URL
Tries to find the file specified from filesystem or classpath.static URL
Tries to find the directory specified from filesystem or classpath.static URL
Tries to find the directory specified from filesystem or classpath.static String
Finds and loads a file.static String
Finds and loads a file.static InputStream
Tries to find the file specified from filesystem or classpath.static InputStream
Tries to find the file specified from filesystem or classpath.
-
Constructor Details
-
FileFinder
public FileFinder()
-
-
Method Details
-
find
Tries to find the file specified from filesystem or classpath.- Parameters:
name
- - name of file, can be fully qualified- Returns:
- URL to the file
- See Also:
-
findDir
Tries to find the directory specified from filesystem or classpath.- Parameters:
name
- - name of directory, can be fully qualified- Returns:
- URL to the directory
- See Also:
-
find
Tries to find the file specified from filesystem or classpath.The file will be searched based on the following procedure:
- Try to find the file in current working dir (unless absolute path is given).
- Try to fine the file in package of the class given as argument using the default class loader
- Try to find the file in parent packages of the class given as argument using the default class loader
- Try to fine the file in package of the class given as argument using the context class loader
- Try to find the file in parent packages of the class given as argument using the context class loader
- Repeat the procedure by trying to find the file with a prepended slash.
- Parameters:
name
- - name of file, can be fully qualifiedclazz
- - class to get the class loader from- Returns:
- URL to the file
-
findDir
Tries to find the directory specified from filesystem or classpath.The directory will be searched based on the following procedure:
- Try to find the dir in current working dir (unless absolute path is given).
- Try to fine the dir in package of the class given as argument using the default class loader
- Try to find the dir in parent packages of the class given as argument using the default class loader
- Try to fine the dir in package of the class given as argument using the context class loader
- Try to find the dir in parent packages of the class given as argument using the context class loader
- Repeat the procedure by trying to find the dir with a prepended slash.
- Parameters:
name
- - name of dir, can be fully qualifiedclazz
- - class to get the class loader from- Returns:
- URL to the dir
-
find
Tries to find the file or directory specified from filesystem or classpath.The file/directory will be searched based on the following procedure:
- Try to find the file/dir in current working dir (unless absolute path is given).
- Try to fine the file/dir in package of the class given as argument using the default class loader
- Try to find the file/dir in parent packages of the class given as argument using the default class loader
- Try to fine the file/dir in package of the class given as argument using the context class loader
- Try to find the file/dir in parent packages of the class given as argument using the context class loader
- Repeat the procedure by trying to find the file/dir with a prepended slash.
- Parameters:
name
- - name of file or directory, can be fully qualifiedclazz
- - class to get the class loader fromfindFiles
- -true
when files shall be found,false
when directories are to be found- Returns:
- URL to the file or directory
-
open
Tries to find the file specified from filesystem or classpath.- Parameters:
name
- - name of file, can be fully qualified- Returns:
- stream to the file
- Throws:
IOException
- when file cannot be opened
-
open
Tries to find the file specified from filesystem or classpath.- Parameters:
name
- - name of file, can be fully qualifiedclazz
- class to get the class loader from- Returns:
- stream to the file
- Throws:
IOException
- when file cannot be opened- See Also:
-
load
Finds and loads a file.- Parameters:
name
- - name of file- Returns:
- contents of file
- Throws:
IOException
- when file cannot be opened- See Also:
-
load
Finds and loads a file.- Parameters:
name
- - name of fileclazz
- class to get the class loader from- Returns:
- contents of file
- Throws:
IOException
- when file cannot be opened- See Also:
-