@NotThreadSafe public final class UriEncoder extends Object
UriBuilder,
UriDecoder| Modifier and Type | Class and Description |
|---|---|
static class |
UriEncoder.Encoding
Defines the escape sequences for illegal characters in various URI
components.
|
| Modifier and Type | Field and Description |
|---|---|
static Charset |
UTF8
The default character set.
|
| Constructor and Description |
|---|
UriEncoder()
Constructs a new URI codec which uses the UTF-8 character set to encode
non-US-ASCII characters.
|
UriEncoder(boolean raw)
Constructs a new URI codec which uses the UTF-8 character set to encode
non-US-ASCII characters.
|
UriEncoder(Charset charset)
Constructs a new URI codec which uses the given character set to encode
non-US-ASCII characters.
|
UriEncoder(Charset charset,
boolean raw)
Constructs a new URI codec which uses the given character set to encode
non-US-ASCII characters.
|
| Modifier and Type | Method and Description |
|---|---|
String |
encode(String dS,
UriEncoder.Encoding comp)
Encodes all characters in the string
dS which are illegal within
the URI component comp. |
StringBuilder |
encode(String dS,
UriEncoder.Encoding comp,
StringBuilder eS)
Encodes all characters in the string
dS which are illegal within
the URI component comp to the string builder eS. |
public static final Charset UTF8
public UriEncoder()
UriEncoder(UTF8, false).public UriEncoder(boolean raw)
UriEncoder(UTF8, false).raw - If true, then the '%' character doesn't get
quoted.public UriEncoder(@CheckForNull Charset charset)
UriEncoder(charset, false).charset - the character set to use for encoding non-US-ASCII
characters.
If this parameter is null,
then non-US-ASCII characters will get encoded to UTF-8
if and only if Character.isISOControl(char) or
Character.isSpaceChar(char) is true,
so that most non-US-ASCII character would get preserved.
Note that providing any other value than null or
UTF-8 will void interoperability with most applications.public UriEncoder(@CheckForNull Charset charset, boolean raw)
charset - the character set to use for encoding non-US-ASCII
characters.
If this parameter is null,
then non-US-ASCII characters will get encoded to UTF-8
if and only if Character.isISOControl(char) or
Character.isSpaceChar(char) is true,
so that most non-US-ASCII character would get preserved.
Note that providing any other value than null or
UTF-8 will void interoperability with most applications.raw - If true, then the '%' character doesn't get
quoted.public String encode(String dS, UriEncoder.Encoding comp)
dS which are illegal within
the URI component comp.
Note that calling this method on an already encoded string escapes any
escape sequences again, that is, each occurence of the character
'%' is substituted with the string "%25" again.
dS - the decoded string to encode.comp - the URI component to encode.IllegalArgumentException - on any encoding error with a
URISyntaxException as its
cause.
This exception should never occur if the character set of this
codec is UTF-8.@CheckForNull public StringBuilder encode(String dS, UriEncoder.Encoding comp, @CheckForNull StringBuilder eS) throws URISyntaxException
dS which are illegal within
the URI component comp to the string builder eS.
Note that calling this method on an already encoded string escapes
any escape sequences again, that is, each occurence of the character
'%' is substituted with the string "%25" again.
dS - the decoded string to encode.comp - the URI component to encode.eS - the string builder to which all encoded characters shall get
appended.dS contains only legal characters for the URI
component comp, then null gets returned.
Otherwise, if eS is not null, then it gets
returned with all encoded characters appended to it.
Otherwise, a temporary string builder gets returned which solely
contains all encoded characters.
This temporary string builder may get cleared and reused upon
the next call to any method of this object.URISyntaxException - on any encoding error.
This exception should never occur if the character set of this
codec is UTF-8.
If it occurs however, eS is left in an undefined state.Copyright © 2005-2013 Schlichtherle IT Services. All Rights Reserved.