Modifier and Type | Method and Description |
---|---|
static String |
canonicalize(String path)
Returns the canonical form of the specified path, where
".." and "." path names are dereferenced, and redundant
'/' (or '\' for Windows) path separators are removed. |
static StringBuilder |
canonicalize(StringBuilder path)
Returns the canonical form of the specified path, where
".." and "." path names are dereferenced, and redundant
'/' path separators are removed. |
static String |
getCanonicalParent(String path)
Returns the canonical pathname of the parent of
path , or null if path does not name a parent directory. |
static String |
getName(String path)
Returns the name of the file or directory denoted by the specified pathname.
|
static String |
getParent(String path)
Returns the pathname of the parent of
path , or null if path does not name a parent directory. |
static String |
getProtocol(String path)
Returns the protocol section of the specified path, or
null if a protocol section does not exist. |
static String |
getSimpleName(String path)
Returns the simple name of the file or directory denoted by the specified pathname.
|
static boolean |
isAbsolute(String path)
Tests whether the specified string represents an absolute path, either system or public.
|
static boolean |
isAbsoluteLocal(String path)
Tests whether the specified string represents an absolute local file path.
|
static boolean |
isAbsoluteLocalUnix(String path)
Tests whether the specified string represents an absolute UNIX file path.
|
static boolean |
isAbsoluteLocalURL(String path)
Tests whether the specified string is an URL that represents an absolute local file path.
|
static boolean |
isAbsoluteLocalWindows(String path)
Tests whether the specified string represents an absolute Windows file path.
|
static boolean |
isAbsolutePublicId(String path)
Tests whether the specified string represents an absolute public identifier.
|
static boolean |
isAbsoluteSystemId(String path)
Tests whether the specified string represents an absolute system identifier.
|
static String |
newPath(String parent,
String child)
Creates a path string from a parent pathname string and a child pathname string.
|
public static boolean isAbsoluteLocalURL(String path)
For a string to be considered an absolute local URL, it must:
"file"
protocol."localhost"
.path
- The path to test.true
if the specified string is an URL that represents an absolute local file path, otherwise false
.NullPointerException
- If path
is null.public static boolean isAbsoluteLocalUnix(String path)
For a string to be considered an absolute UNIX file path, it must:
'/'
character.'\0'
characters.path
- The path to test.true
if the specified string represents an absolute UNIX file path, otherwise false
.NullPointerException
- If path
is null.public static boolean isAbsoluteLocalWindows(String path)
A valid Windows file path matches the following patterns:
c:\folder\myfile.txt
\\123.123.123.123\share\folder\myfile.txt
\\server\share\folder\myfile.txt
path
- The path to test.true
if the specified string represents an absolute Windows file path, otherwise false
.NullPointerException
- If path
is null.public static boolean isAbsoluteLocal(String path)
For a string to be considered an absolute local file path, it must:
isAbsoluteLocalURL(String)
isAbsoluteLocalWindows(String)
isAbsoluteLocalUnix(String)
path
- The path to test.true
if the specified string represents an absolute local file path, otherwise false
.NullPointerException
- If path
is null.public static boolean isAbsoluteSystemId(String path)
This method does not perform strict path validation, but merely inspects its prefix to match known absolute path patterns.
This method performs the following tests to detect whether the specified string is an absolute path:
'/'
(UNIX paths)."?:\"
, where ?
is a letter, case insensitive (Windows paths).path
- The string to test.true
if the specified string represents an absolute system identifier, otherwise false
.NullPointerException
- If path
is null.public static boolean isAbsolutePublicId(String path)
This method does not perform strict path validation, but merely inspects its prefix to match known absolute path patterns.
This method performs the following tests to detect whether the specified string is an absolute path:
"<protocol>://"
, where <protocol>
is any string matching
[a-zA-Z0-9]+
.path
- The string to test.true
if the specified string represents an absolute public identifier, otherwise false
.NullPointerException
- If path
is null.public static boolean isAbsolute(String path)
This method does not perform strict path validation, but merely inspects its prefix to match known absolute path patterns.
path
- The string to test.true
if the specified string represents an absolute path, either system or public, otherwise false
.NullPointerException
- If path
is null.public static String getProtocol(String path)
null
if a protocol section does not exist.path
- The path from which to get the protocol section.null
if a protocol does not exist.NullPointerException
- If path
is null.public static String newPath(String parent, String child)
This method operates with the following behavior:
child
is empty then this method returns parent
.parent
is null or empty then this method returns child
.parent
does not have a trailing slash, and child
does not have a leading slash, one slash is added.parent
has a trailing slash, and child
has a leading slash, one slash is discarded.parent
is determined to be a Windows path, then the '\' character is used as the name separator (in case a
separator character must be inserted); otherwise, '/' is used.
Note: This method does not modify separator characters in any parameter.
child
is absolute then it is converted into a relative pathname in a system-dependent way.child
is resolved against parent
.parent
- The parent pathname string.child
- The child pathname string.NullPointerException
- If parent
or child
is null.isAbsoluteLocalWindows(String)
public static String canonicalize(String path)
".."
and "."
path names are dereferenced, and redundant
'/'
(or '\'
for Windows) path separators are removed.
This implementation differs from File.getCanonicalPath()
by only canonicalizing the superficial form of the specified
path. This implementation does not perform filesystem interaction, for the purpose of operations such as resolving symbolic
links (on UNIX platforms).
path
- The path to canonicalize.".."
and "."
path names are dereferenced, and redundant
'/'
(or '\'
for Windows) path separators are removed.NullPointerException
- If path
is null.public static StringBuilder canonicalize(StringBuilder path)
".."
and "."
path names are dereferenced, and redundant
'/'
path separators are removed.
This implementation differs from File.getCanonicalPath()
by only canonicalizing the superficial form of the specified
path. This implementation does not perform filesystem interaction, for the purpose of operations such as resolving symbolic
links (on UNIX platforms).
path
- The path to canonicalize.path
instance, where ".."
and "."
path names are dereferenced, and redundant
'/'
path separators are removed.NullPointerException
- If path
is null.public static String getParent(String path)
path
, or null
if path
does not name a parent directory.path
- The path string.path
, or null
if path
does not name a parent directory.NullPointerException
- If path
is null.public static String getCanonicalParent(String path)
path
, or null
if path
does not name a parent directory.
In a canonical path, the ".."
and "."
path names are dereferenced, and redundant '/'
path separators
are removed.path
- The path string.path
, or null
if path
does not name a parent directory.NullPointerException
- If path
is null.public static String getName(String path)
path
. If the name sequence of path
is empty, then the empty string is returned.path
- The path string.path
is empty.NullPointerException
- If path
is null.IllegalArgumentException
- If path
is an empty string.public static String getSimpleName(String path)
path
, with its dot-extension removed, if present. If the name sequence of path
is empty, then the
empty string is returned.path
- The path string.path
is empty.NullPointerException
- If path
is null.IllegalArgumentException
- If path
is an empty string.Copyright © 2023 LibJ. All rights reserved.