Class URLEncodedUtils


  • public class URLEncodedUtils
    extends Object
    A collection of utilities for encoding URLs.
    Since:
    4.0
    • Constructor Detail

      • URLEncodedUtils

        public URLEncodedUtils()
    • Method Detail

      • parse

        public static List<NameValuePair> parse​(URI uri,
                                                Charset charset)
        Returns a list of NameValuePairs URI query parameters. By convention, '&' and ';' are accepted as parameter separators.
        Parameters:
        uri - input URI.
        charset - parameter charset.
        Returns:
        list of query parameters.
        Since:
        4.5
      • parse

        public static List<NameValuePair> parse​(HttpEntity entity)
                                         throws IOException
        Returns a list of 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.

        Parameters:
        entity - The entity to parse
        Returns:
        a list of NameValuePair as built from the URI's query portion.
        Throws:
        IOException - If there was an exception getting the entity's data.
      • isEncoded

        public static boolean isEncoded​(HttpEntity entity)
        Returns true if the entity's Content-Type header is application/x-www-form-urlencoded.
      • parse

        @Deprecated
        public static void parse​(List<NameValuePair> parameters,
                                 Scanner scanner,
                                 String charset)
        Adds all parameters within the Scanner to the list of 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:
        parameters - List to add parameters to.
        scanner - Input that contains the parameters to parse.
        charset - Encoding to use when decoding the parameters.
      • parse

        @Deprecated
        public static void parse​(List<NameValuePair> parameters,
                                 Scanner scanner,
                                 String parameterSepartorPattern,
                                 String charset)
        Adds all parameters within the Scanner to the list of 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:
        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.
      • parse

        public static List<NameValuePair> parse​(String s,
                                                Charset charset)
        Returns a list of NameValuePairs URI query parameters. By convention, '&' and ';' are accepted as parameter separators.
        Parameters:
        s - URI query component.
        charset - charset to use when decoding the parameters.
        Returns:
        list of query parameters.
        Since:
        4.2
      • parse

        public 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.
        Parameters:
        s - input text.
        charset - parameter charset.
        separators - parameter separators.
        Returns:
        list of query parameters.
        Since:
        4.3
      • parse

        public static List<NameValuePair> parse​(CharArrayBuffer buf,
                                                Charset charset,
                                                char... separators)
        Returns a list of NameValuePairs parameters.
        Parameters:
        buf - text to parse.
        charset - Encoding to use when decoding the parameters.
        separators - element separators.
        Returns:
        a list of NameValuePair as built from the URI's query portion.
        Since:
        4.4
      • parsePathSegments

        public static List<String> parsePathSegments​(CharSequence s,
                                                     Charset charset)
        Returns a list of URI path segments.
        Parameters:
        s - URI path component.
        charset - parameter charset.
        Returns:
        list of segments.
        Since:
        4.5
      • parsePathSegments

        public static List<String> parsePathSegments​(CharSequence s)
        Returns a list of URI path segments.
        Parameters:
        s - URI path component.
        Returns:
        list of segments.
        Since:
        4.5
      • formatSegments

        public static String formatSegments​(Iterable<String> segments,
                                            Charset charset)
        Returns a string consisting of joint encoded path segments.
        Parameters:
        segments - the segments.
        charset - parameter charset.
        Returns:
        URI path component
        Since:
        4.5
      • formatSegments

        public static String formatSegments​(String... segments)
        Returns a string consisting of joint encoded path segments.
        Parameters:
        segments - the segments.
        Returns:
        URI path component
        Since:
        4.5
      • format

        public 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.
        Parameters:
        parameters - The parameters to include.
        charset - The encoding to use.
        Returns:
        An application/x-www-form-urlencoded string
      • format

        public 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.
        Parameters:
        parameters - The parameters to include.
        parameterSeparator - The parameter separator, by convention, '&' or ';'.
        charset - The encoding to use.
        Returns:
        An application/x-www-form-urlencoded string
        Since:
        4.3
      • format

        public 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.
        Parameters:
        parameters - The parameters to include.
        charset - The encoding to use.
        Returns:
        An application/x-www-form-urlencoded string
        Since:
        4.2
      • format

        public 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.
        Parameters:
        parameters - The parameters to include.
        parameterSeparator - The parameter separator, by convention, '&' or ';'.
        charset - The encoding to use.
        Returns:
        An application/x-www-form-urlencoded string
        Since:
        4.3