Class PercentEncoder


  • public class PercentEncoder
    extends java.lang.Object
    Utility class for percent-encoding (also known as URL encoding) strings.

    This class works basically the same as Java's URLEncoder, except that space characters are percent encoded and not using a plus.

    Unlike Java's URLEncoder this class uses RFC 3986 to determine the unreserved characters(see also https://tools.ietf.org/html/rfc3986#section-2.3)

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String encode​(java.lang.String input, java.lang.String encoding)
      Percent-encode a given input string.
      static java.lang.String encode​(java.lang.String input, java.lang.String encoding, char[] additionalReservedChars)
      Percent-encode a given input string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • encode

        public static java.lang.String encode​(java.lang.String input,
                                              java.lang.String encoding)
        Percent-encode a given input string.
        Parameters:
        input - The input string to percent-encode.
        encoding - Encoding used to encode characters.
        Returns:
        Percent encoded string.
      • encode

        public static java.lang.String encode​(java.lang.String input,
                                              java.lang.String encoding,
                                              char[] additionalReservedChars)
        Percent-encode a given input string.
        Parameters:
        input - The input string to percent-encode.
        encoding - Encoding used to encode characters.
        additionalReservedChars - Characters that should be unreserved, but need to be considered reserved too.
        Returns:
        Percent encoded string.