public class URLEncodedUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CONTENT_TYPE
The default HTML form content type.
|
private static String |
NAME_VALUE_SEPARATOR |
private static BitSet |
PATHSAFE
Characters which are safe to use in a path,
i.e.
|
private static BitSet |
PUNCT
Punctuation characters: , ; : $ & + =
These are the additional characters allowed by userinfo.
|
private static char |
QP_SEP_A |
private static char |
QP_SEP_S |
private static int |
RADIX |
private static BitSet |
RESERVED
Reserved characters, i.e.
|
private static BitSet |
UNRESERVED
Unreserved characters, i.e. alphanumeric, plus: {@code _ - !
|
private static BitSet |
URIC
Characters which are safe to use in a query or a fragment,
i.e.
|
private static BitSet |
URLENCODER
Safe characters for x-www-form-urlencoded data, as per java.net.URLEncoder and browser behaviour,
i.e. alphanumeric plus {@code "-", "_", "
|
private static BitSet |
USERINFO
Characters which are safe to use in userinfo,
i.e.
|
Constructor and Description |
---|
URLEncodedUtils() |
Modifier and Type | Method and Description |
---|---|
private static String |
decodeFormFields(String content,
Charset charset)
Decode/unescape www-url-form-encoded content.
|
private static String |
decodeFormFields(String content,
String charset)
Decode/unescape www-url-form-encoded content.
|
private static String |
encodeFormFields(String content,
Charset charset)
Encode/escape www-url-form-encoded content.
|
private static String |
encodeFormFields(String content,
String charset)
Encode/escape www-url-form-encoded content.
|
(package private) static String |
encPath(String content,
Charset charset)
Encode a String using the
PATHSAFE set of characters. |
(package private) static String |
encUric(String content,
Charset charset)
Encode a String using the
URIC set of characters. |
(package private) static String |
encUserInfo(String content,
Charset charset)
Encode a String using the
USERINFO set of characters. |
static String |
format(Iterable<? extends NameValuePair> parameters,
char parameterSeparator,
Charset charset)
Returns a String that is suitable for use as an
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST. |
static String |
format(Iterable<? extends NameValuePair> parameters,
Charset charset)
Returns a String that is suitable for use as an
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST. |
static String |
format(List<? extends NameValuePair> parameters,
char parameterSeparator,
String charset)
Returns a String that is suitable for use as an
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST. |
static String |
format(List<? extends NameValuePair> parameters,
String charset)
Returns a String that is suitable for use as an
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST. |
static boolean |
isEncoded(HttpEntity entity)
Returns true if the entity's Content-Type header is
application/x-www-form-urlencoded . |
static List<NameValuePair> |
parse(CharArrayBuffer buf,
Charset charset,
char... separators)
Returns a list of
NameValuePairs as parsed from the given string using
the given character encoding. |
static List<NameValuePair> |
parse(HttpEntity entity)
Returns a list of
NameValuePairs as parsed from an HttpEntity . |
static void |
parse(List<NameValuePair> parameters,
Scanner scanner,
String charset)
Deprecated.
(4.4) use
parse(String, java.nio.charset.Charset) |
static void |
parse(List<NameValuePair> parameters,
Scanner scanner,
String parameterSepartorPattern,
String charset)
Deprecated.
|
static List<NameValuePair> |
parse(String s,
Charset charset)
Returns a list of
NameValuePairs as parsed from the given string using the given character
encoding. |
static List<NameValuePair> |
parse(String s,
Charset charset,
char... separators)
Returns a list of
NameValuePairs as parsed from the given string using the given character
encoding. |
static List<NameValuePair> |
parse(URI uri,
Charset charset)
Returns a list of
NameValuePairs as built from the URI's query portion. |
static List<NameValuePair> |
parse(URI uri,
String charsetName)
Deprecated.
4.5 Use
parse(URI, Charset) |
private static String |
urlDecode(String content,
Charset charset,
boolean plusAsBlank)
Decode/unescape a portion of a URL, to use with the query part ensure
plusAsBlank is true. |
private static String |
urlEncode(String content,
Charset charset,
BitSet safechars,
boolean blankAsPlus) |
public static final String CONTENT_TYPE
private static final char QP_SEP_A
private static final char QP_SEP_S
private static final String NAME_VALUE_SEPARATOR
private static final BitSet UNRESERVED
_ - ! . ~ ' ( ) *
This list is the same as the unreserved
list in
RFC 2396
private static final BitSet PUNCT
These are the additional characters allowed by userinfo.
private static final BitSet USERINFO
UNRESERVED
plus PUNCT
uationprivate static final BitSet PATHSAFE
UNRESERVED
plus PUNCT
uation plus / @private static final BitSet URIC
RESERVED
plus UNRESERVED
private static final BitSet URLENCODER
"-", "_", ".", "*"
private static final int RADIX
public URLEncodedUtils()
public static List<NameValuePair> parse(URI uri, String charsetName)
parse(URI, Charset)
public static List<NameValuePair> parse(URI uri, Charset charset)
NameValuePairs
as built from the URI's query portion. For example, a URI
of http://example.org/path/to/file?a=1&b=2&c=3
would return a list of three NameValuePairs, one for a=1,
one for b=2, and one for c=3. By convention, '&'
and ';'
are accepted as parameter separators.
This is typically useful while parsing an HTTP PUT. This API is currently only used for testing.
uri
- URI to parsecharset
- Charset to use while parsing the queryNameValuePair
as built from the URI's query portion.public static List<NameValuePair> parse(HttpEntity entity) throws IOException
NameValuePairs
as parsed from an HttpEntity
.
The encoding is taken from the entity's Content-Encoding header.
This is typically used while parsing an HTTP POST.
entity
- The entity to parseNameValuePair
as built from the URI's query portion.IOException
- If there was an exception getting the entity's data.public static boolean isEncoded(HttpEntity entity)
application/x-www-form-urlencoded
.@Deprecated public static void parse(List<NameValuePair> parameters, Scanner scanner, String charset)
parse(String, java.nio.charset.Charset)
parameters
, as encoded by
encoding
. For example, a scanner containing the string a=1&b=2&c=3
would add the
NameValuePairs
a=1, b=2, and c=3 to the list of parameters. By convention, '&'
and
';'
are accepted as parameter separators.parameters
- List to add parameters to.scanner
- Input that contains the parameters to parse.charset
- Encoding to use when decoding the parameters.@Deprecated public static void parse(List<NameValuePair> parameters, Scanner scanner, String parameterSepartorPattern, String charset)
parse(org.apache.http.util.CharArrayBuffer, java.nio.charset.Charset, char...)
parameters
, as encoded by encoding
. For
example, a scanner containing the string a=1&b=2&c=3
would
add the NameValuePairs
a=1, b=2, and c=3 to the
list of parameters.parameters
- List to add parameters to.scanner
- Input that contains the parameters to parse.parameterSepartorPattern
- The Pattern string for parameter separators, by convention "[&;]"
charset
- Encoding to use when decoding the parameters.public static List<NameValuePair> parse(String s, Charset charset)
NameValuePairs
as parsed from the given string using the given character
encoding. By convention, '&'
and ';'
are accepted as parameter separators.s
- text to parse.charset
- Encoding to use when decoding the parameters.NameValuePair
as built from the URI's query portion.public static List<NameValuePair> parse(String s, Charset charset, char... separators)
NameValuePairs
as parsed from the given string using the given character
encoding.s
- text to parse.charset
- Encoding to use when decoding the parameters.separators
- element separators.NameValuePair
as built from the URI's query portion.public static List<NameValuePair> parse(CharArrayBuffer buf, Charset charset, char... separators)
NameValuePairs
as parsed from the given string using
the given character encoding.buf
- text to parse.charset
- Encoding to use when decoding the parameters.separators
- element separators.NameValuePair
as built from the URI's query portion.public static String format(List<? extends NameValuePair> parameters, String charset)
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.parameters
- The parameters to include.charset
- The encoding to use.application/x-www-form-urlencoded
stringpublic static String format(List<? extends NameValuePair> parameters, char parameterSeparator, String charset)
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.parameters
- The parameters to include.parameterSeparator
- The parameter separator, by convention, '&'
or ';'
.charset
- The encoding to use.application/x-www-form-urlencoded
stringpublic static String format(Iterable<? extends NameValuePair> parameters, Charset charset)
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.parameters
- The parameters to include.charset
- The encoding to use.application/x-www-form-urlencoded
stringpublic static String format(Iterable<? extends NameValuePair> parameters, char parameterSeparator, Charset charset)
application/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.parameters
- The parameters to include.parameterSeparator
- The parameter separator, by convention, '&'
or ';'
.charset
- The encoding to use.application/x-www-form-urlencoded
stringprivate static String urlEncode(String content, Charset charset, BitSet safechars, boolean blankAsPlus)
private static String urlDecode(String content, Charset charset, boolean plusAsBlank)
plusAsBlank
is true.content
- the portion to decodecharset
- the charset to useplusAsBlank
- if true
, then convert '+' to space (e.g. for www-url-form-encoded content), otherwise leave as is.private static String decodeFormFields(String content, String charset)
content
- the content to decode, will decode '+' as spacecharset
- the charset to useprivate static String decodeFormFields(String content, Charset charset)
content
- the content to decode, will decode '+' as spacecharset
- the charset to useprivate static String encodeFormFields(String content, String charset)
Uses the URLENCODER
set of characters, rather than
the UNRESERVED
set; this is for compatibilty with previous
releases, URLEncoder.encode() and most browsers.
content
- the content to encode, will convert space to '+'charset
- the charset to useprivate static String encodeFormFields(String content, Charset charset)
Uses the URLENCODER
set of characters, rather than
the UNRESERVED
set; this is for compatibilty with previous
releases, URLEncoder.encode() and most browsers.
content
- the content to encode, will convert space to '+'charset
- the charset to usestatic String encUserInfo(String content, Charset charset)
USERINFO
set of characters.
Used by URIBuilder to encode the userinfo segment.
content
- the string to encode, does not convert space to '+'charset
- the charset to usestatic String encUric(String content, Charset charset)
URIC
set of characters.
Used by URIBuilder to encode the query and fragment segments.
content
- the string to encode, does not convert space to '+'charset
- the charset to useWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses