Modifier and Type | Method and Description |
---|---|
static String |
decode(String s)
Equivalent to
decode(s, "UTF-8") . |
static String |
decode(String s,
String charset)
Decodes all %HH sequences.
|
static String |
encode(String s)
Equivalent to
encode(s, "UTF-8") . |
static String |
encode(String s,
String charset)
Encodes non-ASCII characters, space characters (according to
java.lang.Character.isSpaceChar) and control characters (according to
java.lang.Character.isISOControl) as %XX bytes.
|
static String |
getBaseName(String path)
Same as
getRawBaseName(java.lang.String) except that the returned value is
decoded using decode(java.lang.String) . |
static String |
getExtension(String path)
Same as
getRawExtension(java.lang.String) except that the returned value is
decoded using decode(java.lang.String) . |
static String |
getFragment(String location)
Same as
getRawFragment(java.lang.String) except that the returned value is
decoded using decode(java.lang.String) . |
static String |
getRawBaseName(String path)
Returns the base name of specified path.
|
static String |
getRawExtension(String path)
Returns the extension of specified path.
|
static String |
getRawFragment(String location)
Returns the fragment component (not including the '#'
delimiter) of specified location if any;
null otherwise. |
static String |
getRawParentPath(String path)
Equivalent to
getRawParentPath(path, true) . |
static String |
getRawParentPath(String path,
boolean trailingSlash)
Returns the parent of specified path.
|
static String |
getRawQuery(String location)
Returns the query component (not including the '?'
delimiter) of specified location if any;
null otherwise. |
static String |
getRawRelativePath(String path,
String basePath)
Returns first path as a path relative to the second path.
|
static String |
joinQuotedComponents(String scheme,
String userName,
String userPassword,
String host,
int port,
String path,
String query,
String fragment)
Joins specified URI components, without attempting to quote them.
|
static String |
quoteFragment(String fragment)
Quotes specified fragment (that is, escapes ``special'' characters).
|
static String |
quoteFullPath(String path)
Quotes specified path (that is, escapes ``special'' characters).
|
static void |
quoteFullPath(String path,
StringBuilder buffer)
Similar tp
quoteFullPath(String) but appends quoted
path to specified buffer. |
static String |
quotePath(String path)
Quotes specified path (that is, escapes ``special'' characters).
|
static String |
quoteQuery(String query)
Quotes specified query (that is, escapes ``special'' characters).
|
static String |
quoteUserInfo(String userInfo)
Quotes specified user info (that is, escapes ``special'' characters).
|
static String |
setExtension(String path,
String extension)
Same as
setRawExtension(java.lang.String, java.lang.String) except that extension is
quoted using quotePath(java.lang.String) . |
static String |
setFragment(String location,
String fragment)
Same as
setRawFragment(java.lang.String, java.lang.String) except that fragment is
quoted using quoteFragment(java.lang.String) . |
static String |
setRawExtension(String path,
String extension)
Changes the extension of specified path to specified extension.
|
static String |
setRawFragment(String location,
String fragment)
Changes the fragment component of specified location to specified
fragment.
|
static String |
setRawQuery(String location,
String query)
Changes the query component of specified location to specified
query.
|
static String |
truncatePath(String path,
int maxLength)
Truncates specified path to get something short enough to be displayed
in the "Recently Opened Files" part of a File menu.
|
public static String getRawParentPath(String path)
getRawParentPath(path, true)
.public static String getRawParentPath(String path, boolean trailingSlash)
Examples:
null
for "/".
null
for "foo".
path
- relative or absolute URI pathtrailingSlash
- if true
, returned path ends with a
trailing '/' characternull
for '/' or if
specified path does not contain the '/' characterpublic static String getBaseName(String path)
getRawBaseName(java.lang.String)
except that the returned value is
decoded using decode(java.lang.String)
.public static String getRawBaseName(String path)
Examples:
path
- relative or absolute URI pathpublic static String getExtension(String path)
getRawExtension(java.lang.String)
except that the returned value is
decoded using decode(java.lang.String)
.public static String getRawExtension(String path)
null
for "/tmp/test".
null
for "~/.profile".
path
- relative or absolute URI path possibly having an extensionnull
otherwisepublic static String setExtension(String path, String extension)
setRawExtension(java.lang.String, java.lang.String)
except that extension is
quoted using quotePath(java.lang.String)
.public static String setRawExtension(String path, String extension)
getRawExtension(java.lang.String)
for a description of the extension of a path.path
- relative or absolute URI pathextension
- new extension. Assumed to have been quoted using
quotePath(java.lang.String)
. May be null
which means: remove the
extension.Returns same path if specified path ends with '/'.
public static String getFragment(String location)
getRawFragment(java.lang.String)
except that the returned value is
decoded using decode(java.lang.String)
.public static String getRawFragment(String location)
null
otherwise.public static String setFragment(String location, String fragment)
setRawFragment(java.lang.String, java.lang.String)
except that fragment is
quoted using quoteFragment(java.lang.String)
.public static String setRawFragment(String location, String fragment)
location
- relative or absolute locationfragment
- new fragment. Assumed to have been quoted using quoteFragment(java.lang.String)
. May be null
which means: remove the
fragment.public static String getRawQuery(String location)
null
otherwise.public static String setRawQuery(String location, String query)
location
- relative or absolute locationquery
- new query. Assumed to have been quoted using quoteQuery(java.lang.String)
. May be null
which means: remove the
query.public static String getRawRelativePath(String path, String basePath)
The returned result resolved against the second path gives back first path. This means that trailing slashes "/" are significant.
Examples:
path
- an absolute URI pathbasePath
- another absolute URI pathpublic static String truncatePath(String path, int maxLength)
path
- relative or absolute URI path to be truncatedmaxLength
- maximum length for truncated (this is just a hint);
typically 40public static String joinQuotedComponents(String scheme, String userName, String userPassword, String host, int port, String path, String query, String fragment)
null
or -1 for missing components.scheme
- scheme or null
userName
- properly quoted user name or null
userPassword
- properly quoted password or null
host
- host or null
port
- port or -1path
- properly quoted path or null
query
- properly quoted query (without '?') or null
fragment
- properly quoted fragment (without '#') or
null
public static String quoteUserInfo(String userInfo)
Use this function separately on the user name and on the user password. That is, do not use it on "name:password".
Like all quote functions, the returned string may contain characters belonging to the other category (e.g. non-ASCII characters).
public static String quotePath(String path)
Use this function separately on each path segment. That is, do not use it on something like "foo/bar/gee".
Like all quote functions, the returned string may contain characters belonging to the other category (e.g. non-ASCII characters).
public static String quoteFullPath(String path)
quotePath(java.lang.String)
which only works for path segments,
this method can be used to quote a relative or absolute path.
Like all quote functions, the returned string may contain characters belonging to the other category (e.g. non-ASCII characters).
public static void quoteFullPath(String path, StringBuilder buffer)
quoteFullPath(String)
but appends quoted
path to specified buffer.public static String quoteQuery(String query)
Like all quote functions, the returned string may contain characters belonging to the other category (e.g. non-ASCII characters).
public static String quoteFragment(String fragment)
Returned string contains only ASCII characters.
Like all quote functions, the returned string may contain characters belonging to the other category (e.g. non-ASCII characters).
public static String decode(String s)
decode(s, "UTF-8")
.public static String decode(String s, String charset)
This function should be used on individual components. For example, it can be used on "foo" and on "bar" and not on "/foo/bar" as a whole.
encode(String, String)
and decode(String, String)
are not inverse operations:
s
- string to be decodedcharset
- the encoding used for characters in the other
category. A superset of US-ASCII.
Examples: "ISO-8859-1" (eacute is represented as "%E9"),
"UTF-8" (eacute is represented as "%C3%A9").
For interoperability with URI
, charset
is required to be "UTF-8".
null
if charset
is an unsupported encodingpublic static String encode(String s)
encode(s, "UTF-8")
.public static String encode(String s, String charset)
encode(String, String)
and decode(String, String)
are not inverse operations:
s
- string to be encodecharset
- the encoding used for the aforementioned
``illegal'' characters. A superset of US-ASCII.
For interoperability with URI
, charset
is required to be "UTF-8".
null
if charset
is an unsupported encoding