Package org.ametys.core.util
Class FilenameUtils
- java.lang.Object
-
- org.ametys.core.util.FilenameUtils
-
public final class FilenameUtils extends Object
Utility class for encoding file names and paths.
These methods are used to provide safe names to be stored on disk.
The encode* methods %-encode all reserved chars, plus the '%' char itself.
The filter* methods replace reserved chars with the '_' char.
Reserved chars are\ / ? : * | " < >
-
-
Field Summary
Fields Modifier and Type Field Description private static Predicate<Character>
_isReserved
static char
REPLACEMENT_CHAR
Character used to replace reserved chars in the filter* methods.
-
Constructor Summary
Constructors Modifier Constructor Description private
FilenameUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static String
_encodePath(String path, Predicate<Character> charactersToKeep, boolean encode)
static String
decode(String source)
Decodes an URI-encoded String.static String
encodeName(String name)
%-encode a file name to be stored on disk.static String
encodePath(String path)
%-encode a file path to be stored on disk.static String
filterName(String name)
Replace reserved characters from a file name with a _.static String
filterPath(String path)
Replace reserved characters from a file path with a _.
-
-
-
Field Detail
-
REPLACEMENT_CHAR
public static final char REPLACEMENT_CHAR
Character used to replace reserved chars in the filter* methods.- See Also:
- Constant Field Values
-
_isReserved
private static Predicate<Character> _isReserved
-
-
Constructor Detail
-
FilenameUtils
private FilenameUtils()
-
-
Method Detail
-
encodePath
public static String encodePath(String path)
%-encode a file path to be stored on disk.- Parameters:
path
- the file path to encode- Returns:
- the encoded file path.
-
encodeName
public static String encodeName(String name)
%-encode a file name to be stored on disk.- Parameters:
name
- the file name to encode- Returns:
- the encoded file name.
-
filterPath
public static String filterPath(String path)
Replace reserved characters from a file path with a _.- Parameters:
path
- the file path to transform- Returns:
- the filtered file path
-
filterName
public static String filterName(String name)
Replace reserved characters from a file name with a _.- Parameters:
name
- the file name to transform- Returns:
- the filtered file name
-
_encodePath
private static String _encodePath(String path, Predicate<Character> charactersToKeep, boolean encode)
-
-