Package oracle.i18n.net
Class URLEncoder
- java.lang.Object
-
- oracle.i18n.net.URLEncoder
-
public class URLEncoder extends Object
TheURLEncoder
contains a utility method for converting aString
object into a MIME format calledx-www-form-urlencoded
format.To convert a
String
object, each character is examined in turn:-
The ASCII characters '
a
' through 'z
', 'A
' through 'Z
', '0
' through '9
', and ".", "-", "", "_" remain the same. -
The space character '
+
'. -
All other characters are converted into the 3-character string
"
%xy
", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character.
When you encode a full set of URL string, for example,
http://www.acme.com/
, it is troublesome to encode special meaning characters such as':'
and'/'
. To avoid encoding, you can set the parameter ofescResChar
tofalse
. The following characters will not be encoded:-
;
- Semicolon (U+003B) -
/
- Forward slash (U+002F) -
?
- Question mark (U+003F) -
:
- Colon (U+003A) -
(
- At sign (U+0040) -
&
- Ampersand (U+0026) -
=
- Equal sign (U+002D) -
+
- Plus sign (U+002B) -
$
- Dollar sign (U+0024) -
,
- Comma (U+002C)
By default,
escResChar
istrue
.For information about URL encode/decode, see RFC 1738.
- Since:
- 10.1.0.2
- See Also:
- RFC 1738
-
The ASCII characters '
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
encode(String s)
Encodes aString
object intox-www-form-urlencoded
format using UTF-8 character set encoding.static String
encode(String s, boolean escResChar)
Encodes aString
object intox-www-form-urlencoded
format using UTF-8 character set encoding.static String
encode(String s, boolean escResChar, String enc)
Encodes astring
object intox-www-form-urlencoded
format.
-
-
-
Method Detail
-
encode
public static String encode(String s)
Encodes aString
object intox-www-form-urlencoded
format using UTF-8 character set encoding. Any reserved characters are encoded.- Parameters:
s
- aString
object to be encoded- Returns:
- the translated
String
object
-
encode
public static String encode(String s, boolean escResChar)
Encodes aString
object intox-www-form-urlencoded
format using UTF-8 character set encoding.escResChar
determines whether it encodes the reserved characters .- Parameters:
s
- aString
ojbect to be translatedescResChar
- determines whether to encode the reserved characters;true
- encode (default),false
- don't encode- Returns:
- the translated
String
object - Throws:
IllegalStateException
- if UTF-8 is not supported by JVM
-
encode
public static String encode(String s, boolean escResChar, String enc) throws UnsupportedEncodingException
Encodes astring
object intox-www-form-urlencoded
format.Currently AL16UTF16(also known as UTF-16BE) is not supported.
- Parameters:
s
- aString
object to be translatedescResChar
- determines whether to encode the reserved characters;true
- encode (default),false
- don't encodeenc
- the name of an Oracle or IANA character set- Returns:
- the translated
String
object - Throws:
UnsupportedEncodingException
- if the character set is not supported
-
-