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.StringexpandTilde(java.lang.String path)Expand the tilde in a String representation of a path by the users home directory, as provided by theuser.homeproperty.static FileSystem[]getLocalFileSystems()Returns all local FileSystems.static java.lang.StringgetLocalRoot(java.lang.String p)Return the locally valid root element of anStringrepresentation of an absolute path.static java.lang.StringgetLocalRootlessPath(java.lang.String path)Return the local root less path of an absolute path.static chargetLocalSeparator()Returns the local file system path separator character.static booleanisLinux()Returns if we are currently running on Linux.static booleanisLinuxRoot(java.lang.String root)Check ifrootonly contains a valid Linux root element, which is "/".static booleanisLocalRoot(java.lang.String root)Check ifrootcontains a locally valid root element, such as "C:" on Windows or "/" on Linux and OSX.static booleanisOSX()Returns if we are currently running on OSX.static booleanisOSXRoot(java.lang.String root)Check ifrootcontains a valid OSX root element, which is "/".static booleanisWindows()Returns if we are currently running on Windows.static booleanisWindowsRoot(java.lang.String root)Check ifrootonly contains a valid Windows root element such as "C:".static booleanstartsWithLinuxRoot(java.lang.String path)Checks if the provide path starts with a valid Linux root, that is "/".static booleanstartWithRoot(java.lang.String path)Checks if the provide path starts with a valid root, such as "/" or "C:".static booleanstartWithWindowsRoot(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 ifrootonly contains a valid Windows root element such as "C:". Ifrootisnullor empty,falsewill be returned. Ifrootcontains more than just a root element,falsewill be returned.- Parameters:
root- The root to check.- Returns:
- If
rootonly contains a valid Windows root element.
-
isLinuxRoot
public static boolean isLinuxRoot(java.lang.String root)
Check ifrootonly contains a valid Linux root element, which is "/". Ifrootisnullor empty,falsewill be returned. Ifrootcontains more than just a root element,falsewill be returned.- Parameters:
root- The root to check.- Returns:
- If
rootonly contains a valid Linux root element.
-
isOSXRoot
public static boolean isOSXRoot(java.lang.String root)
Check ifrootcontains a valid OSX root element, which is "/". Ifrootisnullor empty,falsewill be returned. Ifrootcontains more than just a root element,falsewill be returned.- Parameters:
root- The root to check.- Returns:
- If
rootonly contains a valid OSX root element.
-
isLocalRoot
public static boolean isLocalRoot(java.lang.String root)
Check ifrootcontains a locally valid root element, such as "C:" on Windows or "/" on Linux and OSX. Ifrootisnullor empty,falsewill be returned. Ifrootcontains more than just a root element,falsewill 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
rootonly 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 InvalidLocationExceptionReturn the locally valid root element of anStringrepresentation 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 isnullor 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 providedpathis 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.homeproperty. 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.nameproperty). For example, ifuser.nameis set to "john" anduser.homeis 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.homeproperty is not set, the tilde will not be expanded and the provided path will be returned unchanged. If theuser.nameproperty 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 moreFileSystemsrepresenting each of these roots.- Returns:
- all local FileSystems.
- Throws:
XenonException- If the creation of the FileSystem failed.
-
-