public static class QueryString.Decoder extends Object
This decoder is for one time use only. Create a new instance for each URI:
QueryStringCodec.Decoder decoder = new QueryStringCodec.Decoder("/hello?recipient=world&x=1;y=2"); assert decoder.getPath().equals("/hello"); assert decoder.getParameters().get("recipient").get(0).equals("world"); assert decoder.getParameters().get("x").get(0).equals("1"); assert decoder.getParameters().get("y").get(0).equals("2");This decoder can also decode the content of an HTTP POST request whose content type is application/x-www-form-urlencoded:
QueryStringCodec.Decoder decoder = new QueryStringCodec.Decoder("recipient=world&x=1;y=2", false); ...
QueryString.Encoder
Constructor and Description |
---|
Decoder(String uri)
Creates a new decoder that decodes the specified URI.
|
Decoder(String uri, boolean hasPath)
Creates a new decoder that decodes the specified URI encoded in the specified charset.
|
Decoder(String uri, Charset charset)
Creates a new decoder that decodes the specified URI encoded in the specified charset.
|
Decoder(String uri, Charset charset, boolean hasPath)
Creates a new decoder that decodes the specified URI encoded in the specified charset.
|
Decoder(String uri, Charset charset, boolean hasPath, int maxParams)
Creates a new decoder that decodes the specified URI encoded in the specified charset.
|
Decoder(URI uri)
Creates a new decoder that decodes the specified URI.
|
Decoder(URI uri, Charset charset)
Creates a new decoder that decodes the specified URI encoded in the specified charset.
|
Decoder(URI uri, Charset charset, int maxParams)
Creates a new decoder that decodes the specified URI encoded in the specified charset.
|
Modifier and Type | Method and Description |
---|---|
static String |
decodeComponent(String s)
Decodes a bit of an URL encoded by a browser.
|
static String |
decodeComponent(String s, Charset charset)
Decodes a bit of an URL encoded by a browser.
|
Map<String,List<String>> |
parameters()
Returns the decoded key-value parameter pairs of the URI.
|
String |
path()
Returns the decoded path string of the URI.
|
public Decoder(String uri)
The decoder will assume that the query string is encoded in UTF-8.
uri
- URI
public Decoder(String uri, boolean hasPath)
uri
- URI
hasPath
- Has path?
public Decoder(String uri, Charset charset)
uri
- URI
charset
- Charset
public Decoder(String uri, Charset charset, boolean hasPath)
uri
- URI
charset
- Charset
hasPath
- Has path?
public Decoder(String uri, Charset charset, boolean hasPath, int maxParams)
uri
- URI
charset
- Charset
hasPath
- Has path?
maxParams
- Maximum parameters count
public Decoder(URI uri)
The decoder will assume that the query string is encoded in UTF-8.
uri
- URI
public Decoder(URI uri, Charset charset)
uri
- URI
charset
- Charset
public String path()
public Map<String,List<String>> parameters()
public static String decodeComponent(String s)
This is equivalent to calling decodeComponent(String, Charset)
with the UTF-8 charset (recommended to comply with RFC 3986, Section 2).
s
- The string to decode (can be empty).
s
if there's nothing to decode. If the string to decode is
null
, returns an empty string.
IllegalArgumentException
- if the string contains a malformed escape sequence.
public static String decodeComponent(String s, Charset charset)
The string is expected to be encoded as per RFC 3986, Section 2. This is the encoding used by JavaScript functions encodeURI
and encodeURIComponent
, but not escape
. For example in this encoding, é (in Unicode U+00E9
or in UTF-8 0xC3 0xA9
) is encoded as %C3%A9
or %c3%a9
.
This is essentially equivalent to calling URLDecoder#decode(String, String) URLDecoder.decode(s, charset.name())} except that it's over 2x faster and generates less garbage for the GC. Actually this function doesn't allocate any memory if there's nothing to decode, the argument itself is returned.
s
- The string to decode (can be empty).
charset
- The charset to use to decode the string (should really be
Charsets.UTF_8
.
s
if there's nothing to decode. If the string to decode is
null
, returns an empty string.
IllegalArgumentException
- if the string contains a malformed escape sequence.