Package org.refcodes.filesystem
Class FileSystemUtility
- java.lang.Object
-
- org.refcodes.filesystem.FileSystemUtility
-
public final class FileSystemUtility extends java.lang.Object
The Class FileSystemUtility.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
deleteFiles(FileSystem aFileSystem, java.lang.String aPath, boolean isRecursively)
Deletes the entries found for the given path.static java.lang.String
getName(java.lang.String aKey)
Gets the name portion from the provided key (the key without the path portion).static java.lang.String
getPath(java.lang.String aKey)
Gets the path portion from the provided key (the key without the name portion).static java.lang.String
toKey(java.lang.String aPath, java.lang.String aName)
Creates a key from the given path portion and name portion.static FileHandle
toNormalizedFileHandle(FileHandle aFileHandle, FileSystem aFileSystem)
Test whether the given key may jail break from the name space.static java.lang.String
toNormalizedKey(java.lang.String aKey, FileSystem aFileSystem)
Truncates any prefixed path separator as we assemble our new path with the according namespace in front.static java.lang.String
toNormalizedName(java.lang.String aName, FileSystem aFileSystem)
Truncates any prefixed path separator as we assemble our new path with the according namespace in front.static java.lang.String
toNormalizedPath(java.lang.String aPath)
Normalizes the given path.static java.lang.String
toNormalizedPath(java.lang.String aPath, FileSystem aFileSystem)
Truncates any prefixed path separator as we assemble our new path with the according namespace in front.static java.lang.String
toTruncated(java.lang.String aPath)
Truncates any prefixed path separator as we assemble our new path with the according namespace in front.
-
-
-
Method Detail
-
toNormalizedPath
public static java.lang.String toNormalizedPath(java.lang.String aPath)
Normalizes the given path. Some implementations have problems with a beginning separator character. This method removes the beginning separator, also replaces all "/" to the valid separator and returns the result.- Parameters:
aPath
- The path to be normalized- Returns:
- The normalized path
-
getName
public static java.lang.String getName(java.lang.String aKey)
Gets the name portion from the provided key (the key without the path portion).- Parameters:
aKey
- The key from which to get the name portion- Returns:
- The name portion
-
getPath
public static java.lang.String getPath(java.lang.String aKey)
Gets the path portion from the provided key (the key without the name portion).- Parameters:
aKey
- The key from which to get the path portion- Returns:
- The path portion
-
toKey
public static java.lang.String toKey(java.lang.String aPath, java.lang.String aName)
Creates a key from the given path portion and name portion.- Parameters:
aPath
- The path to useaName
- The name to use- Returns:
- The key
-
deleteFiles
public static void deleteFiles(FileSystem aFileSystem, java.lang.String aPath, boolean isRecursively)
Deletes the entries found for the given path.- Parameters:
aFileSystem
- the file systemaPath
- The path where to look whether there are file (handle)s or not.isRecursively
- When true all children of that path are examined as well.
-
toTruncated
public static java.lang.String toTruncated(java.lang.String aPath)
Truncates any prefixed path separator as we assemble our new path with the according namespace in front.- Parameters:
aPath
- The path to truncate.- Returns:
- The truncated path, e.g. no prefixed path delimiters.
-
toNormalizedPath
public static java.lang.String toNormalizedPath(java.lang.String aPath, FileSystem aFileSystem) throws IllegalPathException
Truncates any prefixed path separator as we assemble our new path with the according namespace in front. Test whether the given path may jail break from the name space. In case this "could" be the case, anIllegalPathException
is thrown.- Parameters:
aPath
- The path to be checked.aFileSystem
- The file system to use to get additional information.- Returns:
- The truncated path.
- Throws:
IllegalPathException
- in case the path may jail break the name space.
-
toNormalizedKey
public static java.lang.String toNormalizedKey(java.lang.String aKey, FileSystem aFileSystem) throws IllegalKeyException
Truncates any prefixed path separator as we assemble our new path with the according namespace in front. Test whether the given key may jail break from the name space. In case this "could" be the case, anIllegalKeyException
is thrown.- Parameters:
aKey
- The key to be checked.aFileSystem
- The file system to use to get additional information.- Returns:
- The truncated key.
- Throws:
IllegalKeyException
- in case the key may jail break the name space.
-
toNormalizedName
public static java.lang.String toNormalizedName(java.lang.String aName, FileSystem aFileSystem) throws IllegalNameException
Truncates any prefixed path separator as we assemble our new path with the according namespace in front. Test whether the given key may jail break from the name space. In case this "could" be the case, anIllegalKeyException
is thrown.- Parameters:
aName
- The key to be checked.aFileSystem
- The file system to use to get additional information.- Returns:
- The truncated key.
- Throws:
IllegalNameException
- in case the name may jail break the name space.
-
toNormalizedFileHandle
public static FileHandle toNormalizedFileHandle(FileHandle aFileHandle, FileSystem aFileSystem) throws IllegalFileHandleException
Test whether the given key may jail break from the name space. In case this "could" be the case, anIllegalKeyException
is thrown.- Parameters:
aFileHandle
- The file handle to be checked.aFileSystem
- The file system to use to get additional information.- Returns:
- the file handle
- Throws:
IllegalFileHandleException
- in case the key may jail break the name space.
-
-