Package com.linkedin.alpini.base.misc
Enum URLCodec
- java.lang.Object
-
- java.lang.Enum<URLCodec>
-
- com.linkedin.alpini.base.misc.URLCodec
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<URLCodec>
public enum URLCodec extends java.lang.Enum<URLCodec>
Copies of the implementation ofURLEncoder.encode(String, String)andURLDecoder.decode(String, String)except with the following changes:- Accept a
Charsetargument for the character set instead of a string which would causeCharset.forName(String)to be called. - Internally use
StringBuilderinstead ofStringBuffer. - These methods no longer throw a checked exception because it
no longer calls
Charset.forName(String). - These methods are annotated with
Nonnullannotations.
-
-
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.CharSequencedecode(java.lang.CharSequence s, java.nio.charset.Charset enc)Decodes aapplication/x-www-form-urlencodedstring using a specific encoding scheme.static java.lang.Stringdecode(java.lang.String s, java.nio.charset.Charset enc)Decodes aapplication/x-www-form-urlencodedstring using a specific encoding scheme.static java.lang.CharSequenceencode(java.lang.CharSequence s, java.nio.charset.Charset charset)Translates a string intoapplication/x-www-form-urlencodedformat using a specific encoding scheme.static java.lang.Stringencode(java.lang.String s, java.nio.charset.Charset charset)Translates a string intoapplication/x-www-form-urlencodedformat using a specific encoding scheme.static URLCodecvalueOf(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.
-
-
-
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 namejava.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 intoapplication/x-www-form-urlencodedformat 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-Stringto 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 intoapplication/x-www-form-urlencodedformat 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-CharSequenceto 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 aapplication/x-www-form-urlencodedstring 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- theStringto decodeenc- 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 aapplication/x-www-form-urlencodedstring 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- theCharSequenceto decodeenc- 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)
-
-