public class URLCodec extends java.lang.Object implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder
This codec is meant to be a replacement for standard Java classes URLEncoder
and
URLDecoder
on older Java platforms, as these classes in Java versions below
1.4 rely on the platform's default charset encoding.
This class is thread-safe since 1.11
Constructor and Description |
---|
URLCodec()
Default constructor.
|
URLCodec(java.lang.String charset)
Constructor which allows for the selection of a default charset.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(byte[] bytes)
Decodes an array of URL safe 7-bit characters into an array of original bytes.
|
java.lang.Object |
decode(java.lang.Object obj)
Decodes a URL safe object into its original form.
|
java.lang.String |
decode(java.lang.String str)
Decodes a URL safe string into its original form using the default string charset.
|
java.lang.String |
decode(java.lang.String str,
java.lang.String charsetName)
Decodes a URL safe string into its original form using the specified encoding.
|
static byte[] |
decodeUrl(byte[] bytes)
Decodes an array of URL safe 7-bit characters into an array of original bytes.
|
byte[] |
encode(byte[] bytes)
Encodes an array of bytes into an array of URL safe 7-bit characters.
|
java.lang.Object |
encode(java.lang.Object obj)
Encodes an object into its URL safe form.
|
java.lang.String |
encode(java.lang.String str)
Encodes a string into its URL safe form using the default string charset.
|
java.lang.String |
encode(java.lang.String str,
java.lang.String charsetName)
Encodes a string into its URL safe form using the specified string charset.
|
static byte[] |
encodeUrl(java.util.BitSet urlsafe,
byte[] bytes)
Encodes an array of bytes into an array of URL safe 7-bit characters.
|
java.lang.String |
getDefaultCharset()
The default charset used for string decoding and encoding.
|
java.lang.String |
getEncoding()
Deprecated.
Use
getDefaultCharset() , will be removed in 2.0. |
public URLCodec()
public URLCodec(java.lang.String charset)
charset
- the default string charset to use.public static final byte[] encodeUrl(java.util.BitSet urlsafe, byte[] bytes)
urlsafe
- bitset of characters deemed URL safebytes
- array of bytes to convert to URL safe characterspublic static final byte[] decodeUrl(byte[] bytes) throws DecoderException
bytes
- array of URL safe charactersDecoderException
- Thrown if URL decoding is unsuccessfulpublic byte[] encode(byte[] bytes)
encode
in interface BinaryEncoder
bytes
- array of bytes to convert to URL safe characterspublic byte[] decode(byte[] bytes) throws DecoderException
decode
in interface BinaryDecoder
bytes
- array of URL safe charactersDecoderException
- Thrown if URL decoding is unsuccessfulpublic java.lang.String encode(java.lang.String str, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
str
- string to convert to a URL safe formcharsetName
- the charset for strjava.io.UnsupportedEncodingException
- Thrown if charset is not supportedpublic java.lang.String encode(java.lang.String str) throws EncoderException
encode
in interface StringEncoder
str
- string to convert to a URL safe formEncoderException
- Thrown if URL encoding is unsuccessfulgetDefaultCharset()
public java.lang.String decode(java.lang.String str, java.lang.String charsetName) throws DecoderException, java.io.UnsupportedEncodingException
str
- URL safe string to convert into its original formcharsetName
- the original string charsetDecoderException
- Thrown if URL decoding is unsuccessfuljava.io.UnsupportedEncodingException
- Thrown if charset is not supportedpublic java.lang.String decode(java.lang.String str) throws DecoderException
decode
in interface StringDecoder
str
- URL safe string to convert into its original formDecoderException
- Thrown if URL decoding is unsuccessfulgetDefaultCharset()
public java.lang.Object encode(java.lang.Object obj) throws EncoderException
encode
in interface Encoder
obj
- string to convert to a URL safe formEncoderException
- Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessfulpublic java.lang.Object decode(java.lang.Object obj) throws DecoderException
decode
in interface Decoder
obj
- URL safe object to convert into its original formDecoderException
- Thrown if the argument is not a String
or byte[]
. Thrown if a failure
condition is encountered during the decode process.public java.lang.String getDefaultCharset()
@Deprecated public java.lang.String getEncoding()
getDefaultCharset()
, will be removed in 2.0.String
encoding used for decoding and encoding."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"