java.lang.Object
org.jorigin.lang.PathUtil
This class provide methods for processing resource pathes (files, URL, URI, ...).
- Since:
- 1.0.0
- Version:
- "1.0.14" - b202111241200L
- Author:
- Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA constant symbolizing a mysql path.static final intA constant symbolizing a samba pathstatic final intA constant symbolizing a system path.static final intA constant symbolizing an unknown pathstatic final intA constant symbolizing a URL path followin the file schemestatic final intA constant symbolizing a URL path followin the http schemestatic final intA constant symbolizing a URL path followin the ftp schemestatic final intA constant symbolizing a URL path followin the sftp scheme -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetDirectory(String path) Get the directory of the path given in parameter.static StringgetExtension(String path) Get the extension of the file located by the path given in parameter.static StringgetFileName(String path) Return the file name pointed by thepathgiven in parameter.static intgetProtocol(String path) Return the protocol of a path.static StringgetStrictFileName(String path) Return the file name pointed by the path without its extension.static booleanisAbsolutePath(String path) Return true if the path given in parameter is absolute.static booleanisAbsoluteURL(String url) Return true if the URL given in parameter is absolutestatic URICreate a well formed URI from a path.static URLReturn a Java URL representing the path given in parameter.static Stringrelativize(String path, String root) Relativize given path against the given rootstatic Stringrelativize(URI uri, URI root) Relativize given uri from the given root.static StringremoveRoot(String path) Remove the root of a Path.static URIResolve the path given in parameter against the root path given.static StringReturn a system path from a non constrained path (uri, url, relative system path, ...)static StringConvert a uri into a valid system path or a distant url path (http, ftp, ...)
-
Field Details
-
SYSTEM
public static final int SYSTEMA constant symbolizing a system path. A system path is a absolute or relative exploitation system expressed path- See Also:
-
URL_FILE
public static final int URL_FILEA constant symbolizing a URL path followin the file scheme- See Also:
-
URL_HTTP
public static final int URL_HTTPA constant symbolizing a URL path followin the ftp scheme- See Also:
-
URL_FTP
public static final int URL_FTPA constant symbolizing a URL path followin the http scheme- See Also:
-
URL_SFTP
public static final int URL_SFTPA constant symbolizing a URL path followin the sftp scheme- See Also:
-
SMB
public static final int SMBA constant symbolizing a samba path- See Also:
-
MYSQL
public static final int MYSQLA constant symbolizing a mysql path.- See Also:
-
UNKNOWN
public static final int UNKNOWNA constant symbolizing an unknown path- See Also:
-
-
Constructor Details
-
PathUtil
public PathUtil()
-
-
Method Details
-
pathToURI
Create a well formed URI from a path. The path can be an absolute or relative system path, an URL (ftp, http, ...). The head of the uri is: file:// for a local uri, http:// and ftp:// for distants URI.- Parameters:
path- String the path to convert into URI.- Returns:
- URI the uri created from the path
-
URIToPath
Convert a uri into a valid system path or a distant url path (http, ftp, ...)- Parameters:
uri- URI uri the uri to convert- Returns:
- String path corresponding to the uri
-
URIToPath
Return a system path from a non constrained path (uri, url, relative system path, ...)- Parameters:
uri- String the path to trasform in system path- Returns:
- String the system path (absolute or relative)
-
getProtocol
Return the protocol of a path. A protocol can be:
PathUtil.SYSTEM if the path is a system dependent path.
PathUtil.URL_FILE if the path is a system url (file:/...).
PathUtil.URL_HTTP if the path is a web path (http://...).
PathUtil.URL_FTP if the path is a web file path (ftp://...).- Parameters:
path- String the path to check.- Returns:
- int one of the integer value described above.
-
isAbsoluteURL
Return true if the URL given in parameter is absolute- Parameters:
url- String the url string to test- Returns:
- boolean true if the url is absolute, false otherwise
-
isAbsolutePath
Return true if the path given in parameter is absolute. A path is absolute if:
On linux system
The path start with/
On windows system
The path start with[A-Z]:- Parameters:
path- String the path to test- Returns:
- boolean true if the path is absolute, false otherwise.
-
relativize
Relativize given uri from the given root.- Parameters:
uri- URI the uri to relativizeroot- URI the root against the relativization is done- Returns:
- String the relative path computed
-
resolve
Resolve the path given in parameter against the root path given. The resolution produce a well formed uri. If a path is needed, the callPathUtil.URIToPath(resolve(uri, root))return the system path result of the resolution.- Parameters:
path- String The path to resolveroot- String The root path used in the resolution- Returns:
- URI the well formed uri, result of the resolution.
-
relativize
Relativize given path against the given root- Parameters:
path- String the path to relativizeroot- String the root against the relativization is done- Returns:
- String the relative path computed
-
getFileName
Return the file name pointed by thepathgiven in parameter. The file name is part of the path folowing the last separator.- Parameters:
path- the path from which the file name have to be extracted.- Returns:
- the file name.
-
getExtension
Get the extension of the file located by the path given in parameter. The extension of the file is the set of digits behind the last "." in the path.- Parameters:
path- the path of the file- Returns:
- the extension of the file.
-
getDirectory
Get the directory of the path given in parameter. If the path point a file or a resource, this method return the directory of the file or resource.- Parameters:
path- the path which the directory has to be extracted.- Returns:
- the directory of the path, or
nullif the path is invalid or have no directory.
-
getStrictFileName
Return the file name pointed by the path without its extension. A file name is the part of tje path folowing the last separator. This method compute the file name of the path using the methodgetFileName(String)and remove the extension of the file name if it exists.- Parameters:
path- the path from which the file name have to be extracted without extension.- Returns:
- the strict file name
- See Also:
-
pathToURL
Return a Java URL representing the path given in parameter. Thepathgiven is normalized to match URL prerequisite (simple slash after scheme, ...). If the path is not normalized, the URL may involve errors in resource processing.- Parameters:
path- the path used to build a valid URL- Returns:
- a valid URL
-
removeRoot
Remove the root of a Path. For example, the methodremoveRoot("C:\path")return the string"path". Under linux, the methodremoveRoot("/path")return the string"path". If the parameter got a scheme (file://, http://, ...) it is removed.- Parameters:
path- the path with a root to remove.- Returns:
- the path without a root.
-