Package nl.esciencecenter.xenon.utils
Class LocalFileSystemUtils
- java.lang.Object
-
- nl.esciencecenter.xenon.utils.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 theuser.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 anString
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 ifroot
only contains a valid Linux root element, which is "/".static boolean
isLocalRoot(java.lang.String root)
Check ifroot
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 ifroot
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 ifroot
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:".
-
-
-
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 ifroot
only contains a valid Windows root element such as "C:". Ifroot
isnull
or empty,false
will be returned. Ifroot
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 ifroot
only contains a valid Linux root element, which is "/". Ifroot
isnull
or empty,false
will be returned. Ifroot
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 ifroot
contains a valid OSX root element, which is "/". Ifroot
isnull
or empty,false
will be returned. Ifroot
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 ifroot
contains a locally valid root element, such as "C:" on Windows or "/" on Linux and OSX. Ifroot
isnull
or empty,false
will be returned. Ifroot
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 anString
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 isnull
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 providedpath
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 theuser.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 theuser.name
property). For example, ifuser.name
is set to "john" anduser.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 isnull
. If theuser.home
property is not set, the tilde will not be expanded and the provided path will be returned unchanged. If theuser.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 moreFileSystems
representing each of these roots.- Returns:
- all local FileSystems.
- Throws:
XenonException
- If the creation of the FileSystem failed.
-
-