public class TokenParams extends Object
This class is useful for header values in the form of
"token; n1=v1; n2=v2 ...", for example
Content-Type: text/plain; charset=UTF-8
Accept-Language: en-us, en;q=0.5 ( multiple TokenParams separated by comma )
See parse(String) and parseCommaSeparated(String).
The parameter names are all converted to lower-case; the token and the parameter values have their case preserved.
Currently we don't support parameter without value, like p1 in
"token; p1; p2=v2".
| Constructor and Description |
|---|
TokenParams(String token,
Map<String,String> params)
Create a TokenParams instance.
|
| Instance Methods | |
|---|---|
String |
token()
The token.
|
Map<String,String> |
params()
The parameters as a Map.
|
String |
param(String name)
Get the value of the parameter with the name.
|
String |
toString()
Return a String in the form of
"token; n1=v1; n2=v2 ...". |
| Static Methods | |
TokenParams |
parse(String headerValue)
Parse a header value in the form of
"token; n1=v1; n2=v2 ...". |
List<TokenParams> |
parseCommaSeparated(String headerValue)
Parse a header value in the form of
"token-params *( , token-params)"
where token-params is in the form of "token *( ; name=value )". |
public String token()
public Map<String,String> params()
All keys in this Map are in lower-case.
Caller should treat the returned Map as read-only.
public String param(String name)
The name should be in lower-case.
public String toString()
"token; n1=v1; n2=v2 ...".
Example strings: "text/plain", "text/plain; charset=UTF-8".
public static TokenParams parse(String headerValue)
"token; n1=v1; n2=v2 ...".
This parser is very loose; caller should validate token and parameters afterwards.
Example headers:
Content-Type: text/plain; charset=UTF-8
Content-Disposition: form-data; name="abc"
public static List<TokenParams> parseCommaSeparated(String headerValue)
"token-params *( , token-params)"
where token-params is in the form of "token *( ; name=value )".
This parser is very loose; caller should validate tokens and parameters afterwards.
Example headers:
Accept-Encoding: gzip, deflate
Accept-Language: en-us, en;q=0.5
All known headers in RFC 2616 that this method may apply:
Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges
Allow Connection
Content-Encoding Content-Language
TE Trailer Transfer-Encoding
Upgrade Vary