@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) @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 |
|---|---|
private static String |
ALPHANUM_CHARS |
private static String |
DEFAULT_LEGAL_CHARS |
private CharsetEncoder |
encoder |
private static char[] |
HEX |
private static String |
MARK_CHARS |
private StringBuilder |
stringBuilder |
private static Charset |
UTF8 |
| Constructor and Description |
|---|
UriEncoder()
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.
|
| 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. |
private static void |
quote(ByteBuffer eB,
StringBuilder eS) |
private static void |
quote(char dc,
StringBuilder eS) |
private static final Charset UTF8
private static final char[] HEX
private static final String ALPHANUM_CHARS
private static final String MARK_CHARS
private static final String DEFAULT_LEGAL_CHARS
@CheckForNull private final CharsetEncoder encoder
@CheckForNull private StringBuilder stringBuilder
public UriEncoder()
public UriEncoder(@CheckForNull
Charset charset)
charset - the character set to use for encoding non-US-ASCII
characters.
If this is null, then this codec preserves non-US-ASCII
characters.
Note that using any other character set than UTF-8 should void
interoperability with most applications!private static void quote(char dc,
StringBuilder eS)
private static void quote(ByteBuffer eB, StringBuilder eS)
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-2011 Schlichtherle IT Services. All Rights Reserved.