Class BasicFileFinder
- All Implemented Interfaces:
FileFinder
FileFinder
.
Specialized behavior can be implemented by overridding the find(String, Locale)
method.
Example:
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.juneau.cp.FileFinder
FileFinder.Builder, FileFinder.Void
-
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor.BasicFileFinder
(FileFinder.Builder builder) Builder-based constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected Optional<InputStream>
The main implementation method for finding files.getCandidateFileNames
(String fileName, Locale locale) Returns the candidate file names for the specified file name in the specified locale.getCandidateLocales
(Locale locale) Returns the candidate locales for the specified locale.final Optional<InputStream>
Returns the contents of the resource with the specified name.Returns the file with the specified name as a string.int
hashCode()
protected boolean
isIgnoredFile
(String name) Returnstrue if the file should be ignored based on file name.protected boolean
isInvalidPath
(String path) Checks for path malformations such as use of".." which can be used to open up security holes.toString()
-
Constructor Details
-
BasicFileFinder
Builder-based constructor.- Parameters:
builder
- The builder object.
-
BasicFileFinder
protected BasicFileFinder()Default constructor.Can be used when providing a subclass that overrides the
find(String, Locale)
method.
-
-
Method Details
-
getStream
Description copied from interface:FileFinder
Returns the contents of the resource with the specified name.- Specified by:
getStream
in interfaceFileFinder
- Parameters:
name
- The resource name. SeeClass.getResource(String)
for format.locale
- The locale of the resource to retrieve.
Ifnull , won't look for localized file names.- Returns:
- The resolved resource contents, or
null if the resource was not found. - Throws:
IOException
- Thrown by underlying stream.
-
getString
Description copied from interface:FileFinder
Returns the file with the specified name as a string.- Specified by:
getString
in interfaceFileFinder
- Parameters:
name
- The file name.locale
- The locale of the resource to retrieve.
Ifnull , won't look for localized file names.- Returns:
- The contents of the file as a string. Assumes UTF-8 encoding.
- Throws:
IOException
- If file could not be read.
-
find
The main implementation method for finding files.Subclasses can override this method to provide their own handling.
- Parameters:
name
- The resource name. SeeClass.getResource(String)
for format.locale
- The locale of the resource to retrieve.
Ifnull , won't look for localized file names.- Returns:
- The resolved resource contents, or
null if the resource was not found. - Throws:
IOException
- Thrown by underlying stream.
-
getCandidateFileNames
Returns the candidate file names for the specified file name in the specified locale.For example, if looking for the
"MyResource.txt" file in the Japanese locale, the iterator will return names in the following order:"MyResource_ja_JP.txt" "MyResource_ja.txt" "MyResource.txt"
If the locale is
null , then it will only return"MyResource.txt" .- Parameters:
fileName
- The name of the file to get candidate file names on.locale
- The locale.
Ifnull , won't look for localized file names.- Returns:
- An iterator of file names to look at.
-
getCandidateLocales
Returns the candidate locales for the specified locale.For example, if
locale is"ja_JP" , then this method will return:"ja_JP" "ja" ""
- Parameters:
locale
- The locale to get the list of candidate locales for.- Returns:
- The list of candidate locales.
-
isInvalidPath
Checks for path malformations such as use of".." which can be used to open up security holes.Default implementation returns
true if the path is any of the following:- Is blank or
null . - Contains
".." (to prevent traversing out of working directory). - Contains
"%" (to prevent URI trickery).
- Parameters:
path
- The path to check.- Returns:
true if the path is invalid.
- Is blank or
-
isIgnoredFile
Returnstrue if the file should be ignored based on file name.- Parameters:
name
- The name to check.- Returns:
true if the file should be ignored.
-
hashCode
-
equals
-
toString
-