Package org.eclipse.jetty.util
Class UrlEncoded
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,List<V>>
-
- org.eclipse.jetty.util.MultiMap<String>
-
- org.eclipse.jetty.util.UrlEncoded
-
public class UrlEncoded extends MultiMap<String> implements Cloneable
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.
NotesThe UTF-8 charset is assumed, unless otherwise defined by either passing a parameter or setting the "org.eclipse.jetty.util.UrlEncoding.charset" System property.
The hashtable either contains String single values, vectors of String or arrays of Strings.
This class is only partially synchronised. In particular, simple get operations are not protected from concurrent updates.
- See Also:
URLEncoder, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description UrlEncoded()UrlEncoded(String query)UrlEncoded(UrlEncoded url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectclone()voiddecode(String query)voiddecode(String query, Charset charset)static voiddecode88591To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys)Decoded parameters to MultiMap, using ISO8859-1 encodings.static StringdecodeString(String encoded)Decode String with % encoding.static StringdecodeString(String encoded, int offset, int length, Charset charset)Decode String with % encoding.static voiddecodeTo(InputStream in, MultiMap<String> map, String charset, int maxLength, int maxKeys)Decoded parameters to Map.static voiddecodeTo(InputStream in, MultiMap<String> map, Charset charset, int maxLength, int maxKeys)Decoded parameters to Map.static voiddecodeTo(String content, MultiMap<String> map, String charset)Decoded parameters to Map.static voiddecodeTo(String content, MultiMap<String> map, Charset charset)Decoded parameters to Map.static voiddecodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys)static voiddecodeUtf8To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys)Decoded parameters to Map.static voiddecodeUtf8To(String query, int offset, int length, MultiMap<String> map)Decoded parameters to Map.static voiddecodeUtf8To(String query, MultiMap<String> map)Stringencode()Encode MultiMap with % encoding for UTF8 sequences.Stringencode(Charset charset)Encode MultiMap with % encoding for arbitrary Charset sequences.Stringencode(Charset charset, boolean equalsForNullValue)Encode MultiMap with % encoding.static Stringencode(MultiMap<String> map, Charset charset, boolean equalsForNullValue)Encode MultiMap with % encoding.static StringencodeString(String string)Perform URL encoding.static StringencodeString(String string, Charset charset)Perform URL encoding.-
Methods inherited from class org.eclipse.jetty.util.MultiMap
add, addAllValues, addValues, addValues, containsSimpleValue, getString, getValue, getValues, put, putAllValues, putValues, putValues, removeValue, toString, toStringArrayMap
-
Methods inherited from class java.util.HashMap
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
-
-
-
Field Detail
-
ENCODING
public static final Charset ENCODING
-
-
Constructor Detail
-
UrlEncoded
public UrlEncoded(UrlEncoded url)
-
UrlEncoded
public UrlEncoded()
-
UrlEncoded
public UrlEncoded(String query)
-
-
Method Detail
-
decode
public void decode(String query)
-
encode
public String encode()
Encode MultiMap with % encoding for UTF8 sequences.- Returns:
- the MultiMap as a string with % encoding
-
encode
public String encode(Charset charset)
Encode MultiMap with % encoding for arbitrary Charset sequences.- Parameters:
charset- the charset to use for encoding- Returns:
- the MultiMap as a string encoded with % encodings
-
encode
public String encode(Charset charset, boolean equalsForNullValue)
Encode MultiMap with % encoding.- Parameters:
charset- the charset to encode withequalsForNullValue- if True, then an '=' is always used, even for parameters without a value. e.g."blah?a=&b=&c=".- Returns:
- the MultiMap as a string encoded with % encodings
-
encode
public static String encode(MultiMap<String> map, Charset charset, boolean equalsForNullValue)
Encode MultiMap with % encoding.- Parameters:
map- the map to encodecharset- the charset to use for encoding (uses default encoding if null)equalsForNullValue- if True, then an '=' is always used, even for parameters without a value. e.g."blah?a=&b=&c=".- Returns:
- the MultiMap as a string encoded with % encodings.
-
decodeTo
public static void decodeTo(String content, MultiMap<String> map, String charset)
Decoded parameters to Map.- Parameters:
content- the string containing the encoded parametersmap- the MultiMap to put parsed query parameters intocharset- the charset to use for decoding
-
decodeTo
public static void decodeTo(String content, MultiMap<String> map, Charset charset)
Decoded parameters to Map.- Parameters:
content- the string containing the encoded parametersmap- the MultiMap to put parsed query parameters intocharset- the charset to use for decoding
-
decodeUtf8To
public static void decodeUtf8To(String query, int offset, int length, MultiMap<String> map)
Decoded parameters to Map.- Parameters:
query- the string containing the encoded parametersoffset- the offset within raw to decode fromlength- the length of the section to decodemap- theMultiMapto populate
-
decode88591To
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- InputSteam to readmap- MultiMap to add parameters tomaxLength- maximum length of form to readmaxKeys- maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode inputstream as ISO8859-1
-
decodeUtf8To
public static void decodeUtf8To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException
Decoded parameters to Map.- Parameters:
in- InputSteam to readmap- MultiMap to add parameters tomaxLength- maximum form length to decodemaxKeys- the maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode input stream
-
decodeUtf16To
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException
- Throws:
IOException
-
decodeTo
public static void decodeTo(InputStream in, MultiMap<String> map, String charset, int maxLength, int maxKeys) throws IOException
Decoded parameters to Map.- Parameters:
in- the stream containing the encoded parametersmap- the MultiMap to decode intocharset- the charset to use for decodingmaxLength- the maximum length of the form to decodemaxKeys- the maximum number of keys to decode- Throws:
IOException- if unable to decode input stream
-
decodeTo
public static void decodeTo(InputStream in, MultiMap<String> map, Charset charset, int maxLength, int maxKeys) throws IOException
Decoded parameters to Map.- Parameters:
in- the stream containing the encoded parametersmap- the MultiMap to decode intocharset- the charset to use for decodingmaxLength- the maximum length of the form to decodemaxKeys- the maximum number of keys to decode- Throws:
IOException- if unable to decode input stream
-
decodeString
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- the encoded string to decode- Returns:
- the decoded string
-
decodeString
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- the encoded string to decodeoffset- the offset in the encoded string to decode fromlength- the length of characters in the encoded string to decodecharset- the charset to use for decoding- Returns:
- the decoded string
-
encodeString
public static String encodeString(String string)
Perform URL encoding.- Parameters:
string- the string to encode- Returns:
- encoded string.
-
encodeString
public static String encodeString(String string, Charset charset)
Perform URL encoding.- Parameters:
string- the string to encodecharset- the charset to use for encoding- Returns:
- encoded string.
-
-