Class UrlEncoded

java.lang.Object
org.eclipse.jetty.util.UrlEncoded

public class UrlEncoded extends Object
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:
  • Field Details

    • ENCODING

      public static final Charset ENCODING
  • Method Details

    • encode

      public static String encode(MultiMap<String> map, Charset charset, boolean equalsForNullValue)
      Encode MultiMap with % encoding.
      Parameters:
      map - the map to encode
      charset - 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

      public static MultiMap<String> decodeQuery(String query)
    • 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.
      Decoded parameters to Map.
      Parameters:
      content - the string containing the encoded parameters
      map - the MultiMap to put parsed query parameters into
      charset - 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 parameters
      map - the MultiMap to put parsed query parameters into
      charset - the charset to use for decoding
    • decodeTo

      public static void decodeTo(String content, MultiMap<String> map, Charset charset, int maxKeys)
      Decoded parameters to Map.
      Parameters:
      content - the string containing the encoded parameters
      map - the MultiMap to put parsed query parameters into
      charset - 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 parameters
      adder - Function to add parameter
      charset - the charset to use for decoding
    • decodeTo

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

      @Deprecated public static void decodeUtf8To(String query, MultiMap<String> map)
      Deprecated.
      Parameters:
      query - the URI query string.
      map - the MultiMap to store the fields.
    • decodeUtf8To

      public static void decodeUtf8To(String query, Fields fields)

      Decodes URI query parameters into a Fields instance.

      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.
      Decoded parameters to Map.
      Parameters:
      query - the string containing the encoded parameters
      offset - the offset within raw to decode from
      length - the length of the section to decode
      map - the MultiMap to populate
    • decodeUtf8To

      public static void decodeUtf8To(String uri, int offset, int length, Fields fields)

      Decodes URI query parameters into a Fields instance.

      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.
    • 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 read
      map - MultiMap to add parameters to
      maxLength - maximum length of form to read or -1 for no limit
      maxKeys - 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 IOException
      Decoded parameters to MultiMap, using ISO8859-1 encodings.
      Parameters:
      in - InputSteam to read
      adder - Function to add parameter
      maxLength - maximum length of form to read or -1 for no limit
      maxKeys - 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, MultiMap<String> map, int maxLength, int maxKeys) throws IOException
      Decoded parameters to Map.
      Parameters:
      in - InputSteam to read
      map - MultiMap to add parameters to
      maxLength - maximum form length to decode or -1 for no limit
      maxKeys - 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 IOException
      Decoded parameters to Map.
      Parameters:
      in - InputSteam to read
      adder - Function to add parameters to
      maxLength - maximum form length to decode or -1 for no limit
      maxKeys - 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

      public static Charset decodeCharset(String charsetName)
      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 parameters
      map - the MultiMap to decode into
      charset - the charset to use for decoding
      maxLength - the maximum length of the form to decode
      maxKeys - 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 IOException
      Decoded parameters to Map.
      Parameters:
      in - the stream containing the encoded parameters
      adder - Function to add a parameter
      charset - the charset to use for decoding
      maxLength - the maximum length of the form to decode
      maxKeys - 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 decode
      offset - the offset in the encoded string to decode from
      length - the length of characters in the encoded string to decode
      charset - the charset to use for decoding
      Returns:
      the decoded string
    • decodeHexByte

      public static byte decodeHexByte(char hi, char lo)
    • 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 encode
      charset - the charset to use for encoding
      Returns:
      encoded string.