Package org.apache.commons.codec.net
Class URLCodec
java.lang.Object
org.apache.commons.codec.net.URLCodec
- All Implemented Interfaces:
- BinaryDecoder,- BinaryEncoder,- Decoder,- Encoder,- StringDecoder,- StringEncoder
public class URLCodec
extends Object
implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder
Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding.
 
 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 as of 1.11
- Since:
- 1.2
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbyte[]decode(byte[] bytes) Decodes an array of URL safe 7-bit characters into an array of original bytes.Decodes a URL safe object into its original form.Decodes a URL safe string into its original form using the default string charset.Decodes a URL safe string into its original form using the specified encoding.static final 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.Encodes an object into its URL safe form.Encodes a string into its URL safe form using the default string charset.Encodes a string into its URL safe form using the specified string charset.static final byte[]Encodes an array of bytes into an array of URL safe 7-bit characters.The default charset used for string decoding and encoding.Deprecated.UsegetDefaultCharset(), will be removed in 2.0.
- 
Field Details- 
ESCAPE_CHARRelease 1.5 made this field final.- See Also:
 
- 
WWW_FORM_URLDeprecated.1.11 Will be removed in 2.0 (CODEC-230)BitSet of www-form-url safe characters. This is a copy of the internal BitSet which is now used for the conversion. Changes to this field are ignored.
- 
charsetDeprecated.TODO: This field will be changed to a private final Charset in 2.0. (CODEC-126)The default charset used for string decoding and encoding.
 
- 
- 
Constructor Details- 
URLCodecpublic URLCodec()Default constructor.
- 
URLCodecConstructor which allows for the selection of a default charset.- Parameters:
- charset- the default string charset to use.
 
 
- 
- 
Method Details- 
decodeUrlDecodes an array of URL safe 7-bit characters into an array of original bytes. Escaped characters are converted back to their original representation.- Parameters:
- bytes- array of URL safe characters
- Returns:
- array of original bytes
- Throws:
- DecoderException- Thrown if URL decoding is unsuccessful
 
- 
encodeUrlEncodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped.- Parameters:
- urlsafe- bitset of characters deemed URL safe
- bytes- array of bytes to convert to URL safe characters
- Returns:
- array of bytes containing URL safe characters
 
- 
decodeDecodes an array of URL safe 7-bit characters into an array of original bytes. Escaped characters are converted back to their original representation.- Specified by:
- decodein interface- BinaryDecoder
- Parameters:
- bytes- array of URL safe characters
- Returns:
- array of original bytes
- Throws:
- DecoderException- Thrown if URL decoding is unsuccessful
 
- 
decodeDecodes a URL safe object into its original form. Escaped characters are converted back to their original representation.- Specified by:
- decodein interface- Decoder
- Parameters:
- obj- URL safe object to convert into its original form
- Returns:
- original object
- Throws:
- DecoderException- Thrown if the argument is not a- Stringor- byte[]. Thrown if a failure condition is encountered during the decode process.
 
- 
decodeDecodes a URL safe string into its original form using the default string charset. Escaped characters are converted back to their original representation.- Specified by:
- decodein interface- StringDecoder
- Parameters:
- str- URL safe string to convert into its original form
- Returns:
- original string
- Throws:
- DecoderException- Thrown if URL decoding is unsuccessful
- See Also:
 
- 
decodepublic String decode(String str, String charsetName) throws DecoderException, UnsupportedEncodingException Decodes a URL safe string into its original form using the specified encoding. Escaped characters are converted back to their original representation.- Parameters:
- str- URL safe string to convert into its original form
- charsetName- the original string charset
- Returns:
- original string
- Throws:
- DecoderException- Thrown if URL decoding is unsuccessful
- UnsupportedEncodingException- Thrown if charset is not supported
 
- 
encodeEncodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped.- Specified by:
- encodein interface- BinaryEncoder
- Parameters:
- bytes- array of bytes to convert to URL safe characters
- Returns:
- array of bytes containing URL safe characters
 
- 
encodeEncodes an object into its URL safe form. Unsafe characters are escaped.- Specified by:
- encodein interface- Encoder
- Parameters:
- obj- string to convert to a URL safe form
- Returns:
- URL safe object
- Throws:
- EncoderException- Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful
 
- 
encodeEncodes a string into its URL safe form using the default string charset. Unsafe characters are escaped.- Specified by:
- encodein interface- StringEncoder
- Parameters:
- str- string to convert to a URL safe form
- Returns:
- URL safe string
- Throws:
- EncoderException- Thrown if URL encoding is unsuccessful
- See Also:
 
- 
encodeEncodes a string into its URL safe form using the specified string charset. Unsafe characters are escaped.- Parameters:
- str- string to convert to a URL safe form
- charsetName- the charset for str
- Returns:
- URL safe string
- Throws:
- UnsupportedEncodingException- Thrown if charset is not supported
 
- 
getDefaultCharsetThe default charset used for string decoding and encoding.- Returns:
- the default string charset.
 
- 
getEncodingDeprecated.UsegetDefaultCharset(), will be removed in 2.0.TheStringencoding used for decoding and encoding.- Returns:
- the encoding.
 
 
-