Package org.eclipse.jetty.util
Class UrlEncoded
java.lang.Object
org.eclipse.jetty.util.UrlEncoded
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.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddecode88591To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) Decoded parameters to MultiMap, using ISO8859-1 encodings.static voiddecode88591To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) Decoded parameters to MultiMap, using ISO8859-1 encodings.static CharsetdecodeCharset(String charsetName) static bytedecodeHexByte(char hi, char lo) decodeQuery(String query) 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, BiConsumer<String, String> adder, Charset 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 voidDecoded parameters to Map.static voidDecoded parameters to Map.static voidDeprecated, for removal: This API element is subject to removal in a future version.static voidDecoded parameters to Map.static voidDecoded parameters to Map.static voiddecodeUtf16To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) static voiddecodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) static voiddecodeUtf8To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) Decoded parameters to Map.static voiddecodeUtf8To(InputStream in, Fields fields, int maxLength, int maxKeys) Decoded parameters to Map.static voiddecodeUtf8To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) Deprecated, for removal: This API element is subject to removal in a future version.usedecodeUtf8To(InputStream, Fields, int, int)instead.static booleandecodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder) Decodes URI query parameters as UTF8 stringstatic booleandecodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder, boolean allowBadPercent, boolean allowBadUtf8, boolean allowTruncatedUtf8) Decodes URI query parameters as UTF8 stringstatic voiddecodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder, boolean allowBadPercent, boolean allowBadUtf8, boolean allowTruncatedUtf8, BiConsumer<String, Boolean> onBadEncoding, BiConsumer<String, Boolean> onBadPercentage, BiConsumer<String, Boolean> onTruncatedUtf8) static voiddecodeUtf8To(String uri, int offset, int length, Fields fields) Decodes URI query parameters into aFieldsinstance.static voiddecodeUtf8To(String query, int offset, int length, MultiMap<String> map) Deprecated.usedecodeUtf8To(String, int, int, Fields)instead.static voiddecodeUtf8To(String query, Fields fields) Decodes URI query parameters into aFieldsinstance.static voiddecodeUtf8To(String query, MultiMap<String> map) Deprecated.usedecodeUtf8To(String, Fields)instead.static StringEncode MultiMap with % encoding.static StringencodeString(String string) Perform URL encoding.static StringencodeString(String string, Charset charset) Perform URL encoding.
-
Field Details
-
ENCODING
-
-
Method Details
-
encode
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.
-
decodeQuery
-
decodeTo
@Deprecated(since="10", forRemoval=true) public static void decodeTo(String content, MultiMap<String> map, String charset) Deprecated, for removal: This API element is subject to removal in a future version.usedecodeTo(String, MultiMap, Charset)insteadDecoded 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
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
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, BiConsumer<String, String> adder, Charset charset, int maxKeys) Decoded parameters to Map.- Parameters:
content- the string containing the encoded parametersadder- Function to add parametercharset- the charset to use for decoding
-
decodeTo
Decoded parameters to Map.- Parameters:
content- the string containing the encoded parametersadder- aBiConsumerto accept the name/value pairs.charset- the charset to use for decoding
-
decodeUtf8To
Deprecated.usedecodeUtf8To(String, Fields)instead.- Parameters:
query- the URI query string.map- theMultiMapto store the fields.
-
decodeUtf8To
Decodes URI query parameters into a
Fieldsinstance.- Parameters:
query- the URI query string.fields- the Fields to store the parameters.
-
decodeUtf8To
@Deprecated public static void decodeUtf8To(String query, int offset, int length, MultiMap<String> map) Deprecated.usedecodeUtf8To(String, int, int, Fields)instead.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
-
decodeUtf8To
Decodes URI query parameters into a
Fieldsinstance.- Parameters:
uri- the URI string.offset- the offset at which query parameters start.length- the length of query parameters string to parse.fields- the Fields to store the parameters.
-
decodeUtf8To
public static boolean decodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder) throws Utf8StringBuilder.Utf8IllegalArgumentExceptionDecodes URI query parameters as UTF8 string
- Parameters:
query- the URI string.offset- the offset at which query parameters start.length- the length of query parameters string to parse.adder- the method to call to add decoded parameters.- Returns:
trueif the string was decoded without any bad UTF-8- Throws:
Utf8StringBuilder.Utf8IllegalArgumentException- if there is illegal UTF-8 and `allowsBadUtf8` isfalse
-
decodeUtf8To
public static boolean decodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder, boolean allowBadPercent, boolean allowBadUtf8, boolean allowTruncatedUtf8) throws Utf8StringBuilder.Utf8IllegalArgumentExceptionDecodes URI query parameters as UTF8 string
- Parameters:
query- the URI string.offset- the offset at which query parameters start.length- the length of query parameters string to parse.adder- the method to call to add decoded parameters.allowBadPercent- iftrueallow bad percent encoding.allowBadUtf8- iftrueallow bad UTF-8 and insert the replacement character.- Returns:
trueif the string was decoded without any bad UTF-8- Throws:
Utf8StringBuilder.Utf8IllegalArgumentException- if there is illegal UTF-8 and `allowsBadUtf8` isfalse
-
decodeUtf8To
public static void decodeUtf8To(String query, int offset, int length, BiConsumer<String, String> adder, boolean allowBadPercent, boolean allowBadUtf8, boolean allowTruncatedUtf8, BiConsumer<String, throws Utf8StringBuilder.Utf8IllegalArgumentExceptionBoolean> onBadEncoding, BiConsumer<String, Boolean> onBadPercentage, BiConsumer<String, Boolean> onTruncatedUtf8) -
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 read or -1 for no limitmaxKeys- maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode the InputStream as ISO8859-1
-
decode88591To
public static void decode88591To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) throws IOExceptionDecoded parameters to MultiMap, using ISO8859-1 encodings.- Parameters:
in- InputSteam to readadder- Function to add parametermaxLength- maximum length of form to read or -1 for no limitmaxKeys- maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode the InputStream as ISO8859-1
-
decodeUtf8To
public static void decodeUtf8To(InputStream in, Fields fields, int maxLength, int maxKeys) throws IOException Decoded parameters to Map.- Parameters:
in- InputSteam to readfields- the Fields to store the parametersmaxLength- maximum form length to decode or -1 for no limitmaxKeys- the maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode the input stream
-
decodeUtf8To
@Deprecated(since="12.0.17", forRemoval=true) public static void decodeUtf8To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.usedecodeUtf8To(InputStream, Fields, int, int)instead.Decoded parameters to Map.- Parameters:
in- InputSteam to readmap- MultiMap to add parameters tomaxLength- maximum form length to decode or -1 for no limitmaxKeys- the maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode the input stream
-
decodeUtf8To
public static void decodeUtf8To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) throws IOExceptionDecoded parameters to Map.- Parameters:
in- InputSteam to readadder- Function to add parameters tomaxLength- maximum form length to decode or -1 for no limitmaxKeys- the maximum number of keys to read or -1 for no limit- Throws:
IOException- if unable to decode the input stream
-
decodeUtf16To
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException - Throws:
IOException
-
decodeUtf16To
public static void decodeUtf16To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) throws IOException- Throws:
IOException
-
decodeCharset
- Parameters:
charsetName- The charset name for decoding or null for the default- Returns:
- A Charset to use for decoding.
-
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
-
decodeTo
public static void decodeTo(InputStream in, BiConsumer<String, String> adder, Charset charset, int maxLength, int maxKeys) throws IOExceptionDecoded parameters to Map.- Parameters:
in- the stream containing the encoded parametersadder- Function to add a parametercharset- 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
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
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
-
decodeHexByte
public static byte decodeHexByte(char hi, char lo) -
encodeString
Perform URL encoding.- Parameters:
string- the string to encode- Returns:
- encoded string.
-
encodeString
Perform URL encoding.- Parameters:
string- the string to encodecharset- the charset to use for encoding- Returns:
- encoded string.
-
decodeTo(String, MultiMap, Charset)instead