Enum URLCodec

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<URLCodec>

    public enum URLCodec
    extends java.lang.Enum<URLCodec>
    Copies of the implementation of URLEncoder.encode(String, String) and URLDecoder.decode(String, String) except with the following changes:
    • Accept a Charset argument for the character set instead of a string which would cause Charset.forName(String) to be called.
    • Internally use StringBuilder instead of StringBuffer.
    • These methods no longer throw a checked exception because it no longer calls Charset.forName(String).
    • These methods are annotated with Nonnull annotations.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      SINGLETON  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.CharSequence decode​(java.lang.CharSequence s, java.nio.charset.Charset enc)
      Decodes a application/x-www-form-urlencoded string using a specific encoding scheme.
      static java.lang.String decode​(java.lang.String s, java.nio.charset.Charset enc)
      Decodes a application/x-www-form-urlencoded string using a specific encoding scheme.
      static java.lang.CharSequence encode​(java.lang.CharSequence s, java.nio.charset.Charset charset)
      Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme.
      static java.lang.String encode​(java.lang.String s, java.nio.charset.Charset charset)
      Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme.
      static URLCodec valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static URLCodec[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • SINGLETON

        public static final URLCodec SINGLETON
    • Method Detail

      • values

        public static URLCodec[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (URLCodec c : URLCodec.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static URLCodec valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • encode

        @Nonnull
        public static java.lang.String encode​(@Nonnull
                                              java.lang.String s,
                                              @Nonnull
                                              java.nio.charset.Charset charset)
        Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.

        Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.

        Parameters:
        s - String to be translated.
        charset - The name of a supported character encoding.
        Returns:
        the translated String.
        See Also:
        URLEncoder.encode(java.lang.String, java.lang.String)
      • encode

        @Nonnull
        public static java.lang.CharSequence encode​(@Nonnull
                                                    java.lang.CharSequence s,
                                                    @Nonnull
                                                    java.nio.charset.Charset charset)
        Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.

        Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.

        Parameters:
        s - CharSequence to be translated.
        charset - The name of a supported character encoding.
        Returns:
        the translated CharSequence. Note that if a conversion was required, the returned CharSequence is shared thread local and that the caller is required to copy it.
        See Also:
        URLEncoder.encode(java.lang.String, java.lang.String)
      • decode

        @Nonnull
        public static java.lang.String decode​(@Nonnull
                                              java.lang.String s,
                                              @Nonnull
                                              java.nio.charset.Charset enc)
        Decodes a application/x-www-form-urlencoded string using a specific encoding scheme. The supplied encoding is used to determine what characters are represented by any consecutive sequences of the form "%xy".

        Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.

        Parameters:
        s - the String to decode
        enc - The name of a supported character encoding.
        Returns:
        the newly decoded String
        See Also:
        URLDecoder.decode(java.lang.String, java.lang.String)
      • decode

        @Nonnull
        public static java.lang.CharSequence decode​(@Nonnull
                                                    java.lang.CharSequence s,
                                                    @Nonnull
                                                    java.nio.charset.Charset enc)
        Decodes a application/x-www-form-urlencoded string using a specific encoding scheme. The supplied encoding is used to determine what characters are represented by any consecutive sequences of the form "%xy".

        Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.

        Parameters:
        s - the CharSequence to decode
        enc - The name of a supported character encoding.
        Returns:
        the newly decoded CharSequence. Note that if a conversion was required, the returned CharSequence is shared thread local and that the caller is required to copy it.
        See Also:
        URLDecoder.decode(java.lang.String, java.lang.String)