Top Description Fields Constructors Methods
org.eclipse.jetty.util

public Class UrlEncoded

extends Object
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .InputStream, .InputStreamReader, .StringWriter, java.nio.charset.CharacterCodingException, .Charset, .StandardCharsets, java.util.List, .Map, java.util.function.BiConsumer, org.slf4j.Logger, .LoggerFactory

Handles coding of MIME "x-www-form-urlencoded".

This class handles the encoding and decoding for either the query string of a URL or the _content of a POST HTTP request.

Notes

The UTF-8 charset is assumed, unless otherwise defined by either passing a parameter or setting the "org.eclipse.jetty.util.UrlEncoding.charset" System property.

See Also
java.net.URLEncoder

Field Summary

Modifier and TypeField and Description
public static final Charset
pack-priv static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
checkMaxKeys(MultiMap<String> map, int maxKeys)

private static void
checkMaxLength(int length, int maxLength)

public static void
decode88591To(InputStream
InputSteam to read
in
,
MultiMap<String>
MultiMap to add parameters to
map
,
int
maximum length of form to read or -1 for no limit
maxLength
,
int
maximum number of keys to read or -1 for no limit
maxKeys
)

Decoded parameters to MultiMap, using ISO8859-1 encodings.

public static Charset

Returns:

A Charset to use for decoding.
decodeCharset
(String
The charset name for decoding or null for the default
charsetName
)

public static byte
decodeHexByte(char hi, char lo)

private static char
decodeHexChar(int hi, int lo)

public static MultiMap<String>
public static String

Returns:

the decoded string
decodeString
(String
the encoded string to decode
encoded
)

Decode String with % encoding.

public static String

Returns:

the decoded string
decodeString
(String
the encoded string to decode
encoded
,
int
the offset in the encoded string to decode from
offset
,
int
the length of characters in the encoded string to decode
length
,
Charset
the charset to use for decoding
charset
)

Decode String with % encoding.

public static void
decodeTo(String
the string containing the encoded parameters
content
,
MultiMap<String>
the MultiMap to put parsed query parameters into
map
,
String
the charset to use for decoding
charset
)

Deprecated for removal since 10. use decodeTo(String, MultiMap, Charset) instead
Decoded parameters to Map.
public static void
decodeTo(String
the string containing the encoded parameters
content
,
MultiMap<String>
the MultiMap to put parsed query parameters into
map
,
Charset
the charset to use for decoding
charset
)

Decoded parameters to Map.

public static void
decodeTo(String
the string containing the encoded parameters
content
,
MultiMap<String>
the MultiMap to put parsed query parameters into
map
,
Charset
the charset to use for decoding
charset
,
int maxKeys)

Decoded parameters to Map.

public static void
decodeTo(String
the string containing the encoded parameters
content
,
BiConsumer<String, String>
a BiConsumer to accept the name/value pairs.
adder
,
Charset
the charset to use for decoding
charset
)

Decoded parameters to Map.

public static void
decodeTo(InputStream
the stream containing the encoded parameters
in
,
MultiMap<String>
the MultiMap to decode into
map
,
Charset
the charset to use for decoding
charset
,
int
the maximum length of the form to decode
maxLength
,
int
the maximum number of keys to decode
maxKeys
)

Decoded parameters to Map.

public static void
decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys)

public static void
decodeUtf8To(String
the URI query string.
query
,
MultiMap<String>
the MultiMap to store the fields.
map
)

Deprecated use decodeUtf8To(String, Fields) instead.
public static void
decodeUtf8To(String
the URI query string.
query
,
Fields
the Fields to store the parameters.
fields
)

Decodes URI query parameters into a Fields instance.

public static void
decodeUtf8To(String
the string containing the encoded parameters
query
,
int
the offset within raw to decode from
offset
,
int
the length of the section to decode
length
,
MultiMap<String>
the MultiMap to populate
map
)

Deprecated use decodeUtf8To(String, int, int, Fields) instead.
Decoded parameters to Map.
public static void
decodeUtf8To(String
the URI string.
uri
,
int
the offset at which query parameters start.
offset
,
int
the length of query parameters string to parse.
length
,
Fields
the Fields to store the parameters.
fields
)

Decodes URI query parameters into a Fields instance.

private static void
decodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder)

public static void
decodeUtf8To(InputStream
InputSteam to read
in
,
MultiMap<String>
MultiMap to add parameters to
map
,
int
maximum form length to decode or -1 for no limit
maxLength
,
int
the maximum number of keys to read or -1 for no limit
maxKeys
)

Decoded parameters to Map.

public static String

Returns:

the MultiMap as a string encoded with % encodings.
encode
(MultiMap<String>
the map to encode
map
,
Charset
the charset to use for encoding (uses default encoding if null)
charset
,
boolean
if True, then an '=' is always used, even for parameters without a value. e.g. "blah?a=&b=&c=".
equalsForNullValue
)

Encode MultiMap with % encoding.

public static String

Returns:

encoded string.
encodeString
(String
the string to encode
string
)

Perform URL encoding.

public static String

Returns:

encoded string.
encodeString
(String
the string to encode
string
,
Charset
the charset to use for encoding
charset
)

Perform URL encoding.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ENCODINGback to summary
public static final Charset ENCODING
LOGback to summary
pack-priv static final Logger LOG

Constructor Detail

UrlEncodedback to summary
private UrlEncoded()

Method Detail

checkMaxKeysback to summary
private static void checkMaxKeys(MultiMap<String> map, int maxKeys)
checkMaxLengthback to summary
private static void checkMaxLength(int length, int maxLength)
decode88591Toback to summary
public static void decode88591To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException

Decoded parameters to MultiMap, using ISO8859-1 encodings.

Parameters
in:InputStream

InputSteam to read

map:MultiMap<String>

MultiMap to add parameters to

maxLength:int

maximum length of form to read or -1 for no limit

maxKeys:int

maximum number of keys to read or -1 for no limit

Exceptions
IOException:
if unable to decode the InputStream as ISO8859-1
decodeCharsetback to summary
public static Charset decodeCharset(String charsetName)
Parameters
charsetName:String

The charset name for decoding or null for the default

Returns:Charset

A Charset to use for decoding.

decodeHexByteback to summary
public static byte decodeHexByte(char hi, char lo)
decodeHexCharback to summary
private static char decodeHexChar(int hi, int lo)
decodeQueryback to summary
public static MultiMap<String> decodeQuery(String query)
decodeStringback to summary
public static String decodeString(String encoded)

Decode String with % encoding. This method makes the assumption that the majority of calls will need no decoding.

Parameters
encoded:String

the encoded string to decode

Returns:String

the decoded string

decodeStringback to summary
public static String decodeString(String encoded, int offset, int length, Charset charset)

Decode String with % encoding. This method makes the assumption that the majority of calls will need no decoding.

Parameters
encoded:String

the encoded string to decode

offset:int

the offset in the encoded string to decode from

length:int

the length of characters in the encoded string to decode

charset:Charset

the charset to use for decoding

Returns:String

the decoded string

decodeToback to summary
public static void decodeTo(String content, MultiMap<String> map, String charset)

Deprecated

for removal since 10.

use decodeTo(String, MultiMap, Charset) instead

Decoded parameters to Map.

Parameters
content:String

the string containing the encoded parameters

map:MultiMap<String>

the MultiMap to put parsed query parameters into

charset:String

the charset to use for decoding

Annotations
@Deprecated
since:10
forRemoval:true
decodeToback to summary
public static void decodeTo(String content, MultiMap<String> map, Charset charset)

Decoded parameters to Map.

Parameters
content:String

the string containing the encoded parameters

map:MultiMap<String>

the MultiMap to put parsed query parameters into

charset:Charset

the charset to use for decoding

decodeToback to summary
public static void decodeTo(String content, MultiMap<String> map, Charset charset, int maxKeys)

Decoded parameters to Map.

Parameters
content:String

the string containing the encoded parameters

map:MultiMap<String>

the MultiMap to put parsed query parameters into

charset:Charset

the charset to use for decoding

decodeToback to summary
public static void decodeTo(String content, BiConsumer<String, String> adder, Charset charset)

Decoded parameters to Map.

Parameters
content:String

the string containing the encoded parameters

adder:BiConsumer<String, String>

a BiConsumer to accept the name/value pairs.

charset:Charset

the charset to use for decoding

decodeToback to summary
public static void decodeTo(InputStream in, MultiMap<String> map, Charset charset, int maxLength, int maxKeys) throws IOException

Decoded parameters to Map.

Parameters
in:InputStream

the stream containing the encoded parameters

map:MultiMap<String>

the MultiMap to decode into

charset:Charset

the charset to use for decoding

maxLength:int

the maximum length of the form to decode

maxKeys:int

the maximum number of keys to decode

Exceptions
IOException:
if unable to decode input stream
decodeUtf16Toback to summary
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException
decodeUtf8Toback to summary
public static void decodeUtf8To(String query, MultiMap<String> map)

Deprecated

use decodeUtf8To(String, Fields) instead.

Parameters
query:String

the URI query string.

map:MultiMap<String>

the MultiMap to store the fields.

Annotations
@Deprecated
decodeUtf8Toback to summary
public static void decodeUtf8To(String query, Fields fields)

Decodes URI query parameters into a Fields instance.

Parameters
query:String

the URI query string.

fields:Fields

the Fields to store the parameters.

decodeUtf8Toback to summary
public static void decodeUtf8To(String query, int offset, int length, MultiMap<String> map)

Decoded parameters to Map.

Parameters
query:String

the string containing the encoded parameters

offset:int

the offset within raw to decode from

length:int

the length of the section to decode

map:MultiMap<String>

the MultiMap to populate

Annotations
@Deprecated
decodeUtf8Toback to summary
public static void decodeUtf8To(String uri, int offset, int length, Fields fields)

Decodes URI query parameters into a Fields instance.

Parameters
uri:String

the URI string.

offset:int

the offset at which query parameters start.

length:int

the length of query parameters string to parse.

fields:Fields

the Fields to store the parameters.

decodeUtf8Toback to summary
private static void decodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder)
decodeUtf8Toback to summary
public static void decodeUtf8To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException

Decoded parameters to Map.

Parameters
in:InputStream

InputSteam to read

map:MultiMap<String>

MultiMap to add parameters to

maxLength:int

maximum form length to decode or -1 for no limit

maxKeys:int

the maximum number of keys to read or -1 for no limit

Exceptions
IOException:
if unable to decode the input stream
encodeback to summary
public static String encode(MultiMap<String> map, Charset charset, boolean equalsForNullValue)

Encode MultiMap with % encoding.

Parameters
map:MultiMap<String>

the map to encode

charset:Charset

the charset to use for encoding (uses default encoding if null)

equalsForNullValue:boolean

if True, then an '=' is always used, even for parameters without a value. e.g. "blah?a=&b=&c=".

Returns:String

the MultiMap as a string encoded with % encodings.

encodeStringback to summary
public static String encodeString(String string)

Perform URL encoding.

Parameters
string:String

the string to encode

Returns:String

encoded string.

encodeStringback to summary
public static String encodeString(String string, Charset charset)

Perform URL encoding.

Parameters
string:String

the string to encode

charset:Charset

the charset to use for encoding

Returns:String

encoded string.