public class

URLCodec

extends Object
implements BinaryDecoder BinaryEncoder StringDecoder StringEncoder
java.lang.Object
   ↳ org.apache.commons.codec.net.URLCodec

Summary

Fields
protected static byte ESCAPE_CHAR Consider this field final.
protected static final BitSet WWW_FORM_URL BitSet of www-form-url safe characters.
protected String charset The default charset used for string decoding and encoding.
Public Constructors
URLCodec()
Default constructor.
URLCodec(String charset)
Constructor which allows for the selection of a default charset
Public Methods
byte[] decode(byte[] bytes)
Decodes an array of URL safe 7-bit characters into an array of original bytes.
Object decode(Object pObject)
Decodes a URL safe object into its original form.
String decode(String pString, String charset)
Decodes a URL safe string into its original form using the specified encoding.
String decode(String pString)
Decodes a URL safe string into its original form using the default string charset.
final 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.
Object encode(Object pObject)
Encodes an object into its URL safe form.
String encode(String pString, String charset)
Encodes a string into its URL safe form using the specified string charset.
String encode(String pString)
Encodes a string into its URL safe form using the default string charset.
final static byte[] encodeUrl(BitSet urlsafe, byte[] bytes)
Encodes an array of bytes into an array of URL safe 7-bit characters.
String getDefaultCharset()
The default charset used for string decoding and encoding.
String getEncoding()
This method is deprecated. use #getDefaultCharset()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.commons.codec.BinaryDecoder
From interface org.apache.commons.codec.BinaryEncoder
From interface org.apache.commons.codec.Decoder
From interface org.apache.commons.codec.Encoder
From interface org.apache.commons.codec.StringDecoder
From interface org.apache.commons.codec.StringEncoder

Fields

protected static byte ESCAPE_CHAR

Consider this field final. The next major release may break compatibility and make this field be final.

protected static final BitSet WWW_FORM_URL

BitSet of www-form-url safe characters.

protected String charset

The default charset used for string decoding and encoding. Consider this field final. The next major release may break compatibility and make this field be final.

Public Constructors

public URLCodec ()

Default constructor.

public URLCodec (String charset)

Constructor which allows for the selection of a default charset

Parameters
charset the default string charset to use.

Public Methods

public byte[] decode (byte[] bytes)

Decodes 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

public Object decode (Object pObject)

Decodes a URL safe object into its original form. Escaped characters are converted back to their original representation.

Parameters
pObject URL safe object to convert into its original form
Returns
  • original object
Throws
DecoderException Thrown if the argument is not a String or byte[]. Thrown if a failure condition is encountered during the decode process.

public String decode (String pString, String charset)

Decodes a URL safe string into its original form using the specified encoding. Escaped characters are converted back to their original representation.

Parameters
pString URL safe string to convert into its original form
charset the original string charset
Returns
  • original string
Throws
DecoderException Thrown if URL decoding is unsuccessful
UnsupportedEncodingException Thrown if charset is not supported

public String decode (String pString)

Decodes a URL safe string into its original form using the default string charset. Escaped characters are converted back to their original representation.

Parameters
pString URL safe string to convert into its original form
Returns
  • original string
Throws
DecoderException Thrown if URL decoding is unsuccessful

public static final byte[] decodeUrl (byte[] bytes)

Decodes 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

public byte[] encode (byte[] bytes)

Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped.

Parameters
bytes array of bytes to convert to URL safe characters
Returns
  • array of bytes containing URL safe characters

public Object encode (Object pObject)

Encodes an object into its URL safe form. Unsafe characters are escaped.

Parameters
pObject 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

public String encode (String pString, String charset)

Encodes a string into its URL safe form using the specified string charset. Unsafe characters are escaped.

Parameters
pString string to convert to a URL safe form
charset the charset for pString
Returns
  • URL safe string
Throws
UnsupportedEncodingException Thrown if charset is not supported

public String encode (String pString)

Encodes a string into its URL safe form using the default string charset. Unsafe characters are escaped.

Parameters
pString string to convert to a URL safe form
Returns
  • URL safe string
Throws
EncoderException Thrown if URL encoding is unsuccessful

public static final byte[] encodeUrl (BitSet urlsafe, byte[] bytes)

Encodes 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

public String getDefaultCharset ()

The default charset used for string decoding and encoding.

Returns
  • the default string charset.

public String getEncoding ()

This method is deprecated.
use #getDefaultCharset()

The String encoding used for decoding and encoding.

Returns
  • Returns the encoding.