public class NetUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static NetUtil |
NU |
protected static char |
SLASH |
Modifier | Constructor and Description |
---|---|
protected |
NetUtil() |
Modifier and Type | Method and Description |
---|---|
java.net.URI |
asURI(java.lang.String uriString)
Returns the given string as URI if possible.
|
java.net.URL |
asURL(java.lang.String urlString)
Returns the given string as URL if possible.
|
boolean |
close(java.io.Closeable closeable)
Silently closes the given object.
|
static NetUtil |
current()
Returns the only instance this class supports (design pattern "Singleton")
|
protected StringUtil |
str() |
java.lang.String |
urlDecode(java.lang.String string,
java.nio.charset.Charset charset)
Returns the given string character and URL decoded.
|
java.lang.String |
urlEncode(java.lang.String string,
java.nio.charset.Charset charset)
Returns the given string character and URL encoded.
|
java.lang.String |
withLeadingSlash(java.lang.String string)
Returns the given string guaranteed with a leading slash.
|
java.lang.String |
withoutLeadingSlash(java.lang.String string)
Returns the given string guaranteed with no leading slash.
|
java.lang.String |
withoutTrailingSlash(java.lang.String string)
Returns the given string guaranteed with no trailing slash.
|
java.lang.String |
withTrailingSlash(java.lang.String string)
Returns the given string guaranteed with a trailing slash.
|
public static final NetUtil NU
protected static final char SLASH
public static NetUtil current()
public boolean close(java.io.Closeable closeable)
closeable
- The object to close (may be null).public java.lang.String urlEncode(java.lang.String string, java.nio.charset.Charset charset)
string
- The string to be encoded (if null, null will be returned).charset
- The character encoding to be used on the string before doing the URL encoding (must not be null).public java.lang.String urlDecode(java.lang.String string, java.nio.charset.Charset charset)
string
- The string to be decoded (if null, null will be returned).charset
- The character encoding to be used on the string after the URL decoding (must not be null).public java.lang.String withLeadingSlash(java.lang.String string)
string
- The string that should have a leading slash (must not be null).public java.lang.String withTrailingSlash(java.lang.String string)
string
- The string that should have a trailing slash (must not be null).public java.lang.String withoutLeadingSlash(java.lang.String string)
string
- The string that should not have a leading slash (must not be null).public java.lang.String withoutTrailingSlash(java.lang.String string)
string
- The string that should not have a trailing slash (must not be null).public java.net.URI asURI(java.lang.String uriString)
uriString
- The string to be converted to a URI (must not be null).InvalidUrlException
- if the given string is no valid URI.public java.net.URL asURL(java.lang.String urlString)
urlString
- The string to be converted to a URL (must not be null).InvalidUrlException
- if the given string is no valid URL.protected StringUtil str()