Class FileSystemUtility

java.lang.Object
org.refcodes.filesystem.FileSystemUtility

public final class FileSystemUtility extends Object
The Class FileSystemUtility.
  • Method Details

    • toNormalizedPath

      public static String toNormalizedPath(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 String getName(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 String getPath(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 String toKey(String aPath, String aName)
      Creates a key from the given path portion and name portion.
      Parameters:
      aPath - The path to use
      aName - The name to use
      Returns:
      The key
    • deleteFiles

      public static void deleteFiles(FileSystem aFileSystem, String aPath, boolean isRecursively)
      Deletes the entries found for the given path.
      Parameters:
      aFileSystem - the file system
      aPath - 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 String toTruncated(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 String toNormalizedPath(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, an IllegalPathException 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 String toNormalizedKey(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, an IllegalKeyException 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 String toNormalizedName(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, an IllegalKeyException 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 IllegalFileException
      Test whether the given key may jail break from the name space. In case this "could" be the case, an IllegalKeyException 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:
      IllegalFileException - in case the key may jail break the name space.