Class LocalFileSystemUtils


  • public class LocalFileSystemUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String expandTilde​(java.lang.String path)
      Expand the tilde in a String representation of a path by the users home directory, as provided by the user.home property.
      static FileSystem[] getLocalFileSystems()
      Returns all local FileSystems.
      static java.lang.String getLocalRoot​(java.lang.String p)
      Return the locally valid root element of an String representation of an absolute path.
      static java.lang.String getLocalRootlessPath​(java.lang.String path)
      Return the local root less path of an absolute path.
      static char getLocalSeparator()
      Returns the local file system path separator character.
      static boolean isLinux()
      Returns if we are currently running on Linux.
      static boolean isLinuxRoot​(java.lang.String root)
      Check if root only contains a valid Linux root element, which is "/".
      static boolean isLocalRoot​(java.lang.String root)
      Check if root contains a locally valid root element, such as "C:" on Windows or "/" on Linux and OSX.
      static boolean isOSX()
      Returns if we are currently running on OSX.
      static boolean isOSXRoot​(java.lang.String root)
      Check if root contains a valid OSX root element, which is "/".
      static boolean isWindows()
      Returns if we are currently running on Windows.
      static boolean isWindowsRoot​(java.lang.String root)
      Check if root only contains a valid Windows root element such as "C:".
      static boolean startsWithLinuxRoot​(java.lang.String path)
      Checks if the provide path starts with a valid Linux root, that is "/".
      static boolean startWithRoot​(java.lang.String path)
      Checks if the provide path starts with a valid root, such as "/" or "C:".
      static boolean startWithWindowsRoot​(java.lang.String path)
      Checks if the provide path starts with a valid Windows root, for example "C:".
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isWindows

        public static boolean isWindows()
        Returns if we are currently running on Windows.
        Returns:
        if we are currently running on Window.
      • isOSX

        public static boolean isOSX()
        Returns if we are currently running on OSX.
        Returns:
        if we are currently running on OSX.
      • isLinux

        public static boolean isLinux()
        Returns if we are currently running on Linux.
        Returns:
        if we are currently running on Linux.
      • isWindowsRoot

        public static boolean isWindowsRoot​(java.lang.String root)
        Check if root only contains a valid Windows root element such as "C:". If root is null or empty, false will be returned. If root contains more than just a root element, false will be returned.
        Parameters:
        root - The root to check.
        Returns:
        If root only contains a valid Windows root element.
      • isLinuxRoot

        public static boolean isLinuxRoot​(java.lang.String root)
        Check if root only contains a valid Linux root element, which is "/". If root is null or empty, false will be returned. If root contains more than just a root element, false will be returned.
        Parameters:
        root - The root to check.
        Returns:
        If root only contains a valid Linux root element.
      • isOSXRoot

        public static boolean isOSXRoot​(java.lang.String root)
        Check if root contains a valid OSX root element, which is "/". If root is null or empty, false will be returned. If root contains more than just a root element, false will be returned.
        Parameters:
        root - The root to check.
        Returns:
        If root only contains a valid OSX root element.
      • isLocalRoot

        public static boolean isLocalRoot​(java.lang.String root)
        Check if root contains a locally valid root element, such as "C:" on Windows or "/" on Linux and OSX. If root is null or empty, false will be returned. If root contains more than just a root element, false will be returned. Note that the result of this method depends on the OS the application is running on.
        Parameters:
        root - The root to check.
        Returns:
        If root only contains a valid OSX root element.
      • startsWithLinuxRoot

        public static boolean startsWithLinuxRoot​(java.lang.String path)
        Checks if the provide path starts with a valid Linux root, that is "/".
        Parameters:
        path - The path to check.
        Returns:
        If the provide path starts with a valid Linux root.
      • startWithWindowsRoot

        public static boolean startWithWindowsRoot​(java.lang.String path)
        Checks if the provide path starts with a valid Windows root, for example "C:".
        Parameters:
        path - The path to check.
        Returns:
        If the provide path starts with a valid Windows root.
      • startWithRoot

        public static boolean startWithRoot​(java.lang.String path)
        Checks if the provide path starts with a valid root, such as "/" or "C:".
        Parameters:
        path - The path to check.
        Returns:
        If the provide path starts with a valid root.
      • getLocalRoot

        public static java.lang.String getLocalRoot​(java.lang.String p)
                                             throws InvalidLocationException
        Return the locally valid root element of an String representation of an absolute path. Examples of a root elements are "/" or "C:". If the provided path does not contain a locally valid root element, an exception will be thrown. For example, providing "/user/local" will return "/" on Linux or OSX, but throw an exception on Windows; providing "C:\test" will return "C:" on Windows but throw an exception on Linux or OSX. If the provided string is null or empty, the default root element for this OS will be returned, i.e,. "/" on Linux or OSX and "C:" on windows.
        Parameters:
        p - The absolute path for which to determine the root element.
        Returns:
        The locally valid root element.
        Throws:
        InvalidLocationException - If the provided path is not absolute, or does not contain a locally valid root.
      • expandTilde

        public static java.lang.String expandTilde​(java.lang.String path)
        Expand the tilde in a String representation of a path by the users home directory, as provided by the user.home property. The tilde will only be replaced if it is the first character in the path and either the only character in the path or directly followed by the local separator character or directly followed by the local user name (as provided by the user.name property). For example, if user.name is set to "john" and user.home is set to "/home/john", then "~" will be expanded to "/home/john", "~/foo" or "~john/foo" will be expanded to "/home/john/foo". However, in paths like "/foo/bar", "~matt/foo" or "/foo/~" the tilde will not be expanded, and the provided path is returned unchanged. This includes a path that is null. If the user.home property is not set, the tilde will not be expanded and the provided path will be returned unchanged. If the user.name property is not set, the combined tilde-username expansion will not be performed.
        Parameters:
        path - the path in which to replace the tilde (if possible).
        Returns:
        the path with the tilde replaced by the user home property, or the unchanged path if replacement was not triggered.
      • getLocalRootlessPath

        public static java.lang.String getLocalRootlessPath​(java.lang.String path)
        Return the local root less path of an absolute path.
        Parameters:
        path - The absolute path from which to remove the root element.
        Returns:
        The path without the root element.
      • getLocalSeparator

        public static char getLocalSeparator()
        Returns the local file system path separator character.
        Returns:
        The local file system path separator character.
      • getLocalFileSystems

        public static FileSystem[] getLocalFileSystems()
                                                throws XenonException
        Returns all local FileSystems. This method detects all local file system roots, and returns one or more FileSystems representing each of these roots.
        Returns:
        all local FileSystems.
        Throws:
        XenonException - If the creation of the FileSystem failed.