public class URLCodec extends Object
Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding.
For more detailed information please refer to Chapter 17.13.4 'Form content types' of the HTML 4.01 Specification
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.
Constructor and Description |
---|
URLCodec() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
decode(byte[] bytes)
Decodes an array of URL safe 7-bit characters into an array of
original bytes.
|
static Object |
decode(Object pObject)
Decodes a URL safe object into its original form.
|
static String |
decode(String pString)
Decodes a URL safe string into its original form using the default
string charset.
|
static String |
decode(String pString,
String charset)
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.
|
static byte[] |
encode(byte[] bytes)
Encodes an array of bytes into an array of URL safe 7-bit
characters.
|
static byte[] |
encode(byte[] bytes,
boolean withSpacesAsHexValue)
Encodes an array of bytes into an array of URL safe 7-bit
characters.
|
static Object |
encode(Object pObject)
Encodes an object into its URL safe form.
|
static Object |
encode(Object pObject,
boolean withSpacesAsHexValue)
Encodes an object into its URL safe form.
|
static String |
encode(String pString)
Encodes a string into its URL safe form using the default string
charset.
|
static String |
encode(String pString,
boolean withSpacesAsHexValue)
Encodes a string into its URL safe form using the default string
charset.
|
static String |
encode(String pString,
String charset)
Encodes a string into its URL safe form using the specified
string charset.
|
static String |
encode(String pString,
String charset,
boolean withSpacesAsHexValue)
Encodes a string into its URL safe form using the specified
string charset.
|
static byte[] |
encodeUrl(BitSet urlsafe,
byte[] bytes)
Encodes an array of bytes into an array of URL safe 7-bit
characters.
|
public static byte[] encodeUrl(BitSet urlsafe, byte[] bytes)
urlsafe
- bitset of characters deemed URL safebytes
- array of bytes to convert to URL safe characterspublic static byte[] decodeUrl(byte[] bytes) throws UnsupportedEncodingException
bytes
- array of URL safe charactersUnsupportedEncodingException
- Thrown if URL decoding is unsuccessfulpublic static byte[] encode(byte[] bytes)
bytes
- array of bytes to convert to URL safe characterspublic static byte[] encode(byte[] bytes, boolean withSpacesAsHexValue)
withSpacesAsHexValue
- if true, spaces will be encoded with their hex value (%20), otherwise they're encoded with '+' character.bytes
- array of bytes to convert to URL safe characterspublic static byte[] decode(byte[] bytes) throws UnsupportedEncodingException
bytes
- array of URL safe charactersUnsupportedEncodingException
- Thrown if URL decoding is unsuccessfulpublic static String encode(String pString, String charset) throws UnsupportedEncodingException
pString
- string to convert to a URL safe formcharset
- the charset for pStringUnsupportedEncodingException
- Thrown if charset is not
supportedpublic static String encode(String pString, String charset, boolean withSpacesAsHexValue) throws UnsupportedEncodingException
pString
- string to convert to a URL safe formcharset
- the charset for pStringwithSpacesAsHexValue
- if true spaces will be encoded with their hex value (%20), otherwise they're encoded with '+' character.UnsupportedEncodingException
- Thrown if charset is not
supportedpublic static String encode(String pString) throws UnsupportedEncodingException
pString
- string to convert to a URL safe formUnsupportedEncodingException
- Thrown if URL encoding is unsuccessfulgetDefaultCharset()
public static String encode(String pString, boolean withSpacesAsHexValue) throws UnsupportedEncodingException
pString
- string to convert to a URL safe formwithSpacesAsHexValue
- if true spaces will be encoded with their hex value (%20), otherwise they're encoded with '+' character.UnsupportedEncodingException
- Thrown if URL encoding is unsuccessfulgetDefaultCharset()
public static String decode(String pString, String charset) throws UnsupportedEncodingException
pString
- URL safe string to convert into its original formcharset
- the original string charsetUnsupportedEncodingException
- Thrown if charset is not
supportedpublic static String decode(String pString) throws UnsupportedEncodingException
pString
- URL safe string to convert into its original formUnsupportedEncodingException
- Thrown if URL decoding is unsuccessfulgetDefaultCharset()
public static Object encode(Object pObject) throws UnsupportedEncodingException
pObject
- string to convert to a URL safe formUnsupportedEncodingException
- Thrown if URL encoding is not
applicable to objects of this type or
if encoding is unsuccessfulpublic static Object encode(Object pObject, boolean withSpacesAsHexValue) throws UnsupportedEncodingException
pObject
- string to convert to a URL safe formwithSpacesAsHexValue
- if true spaces will be encoded with their hex value (%20), otherwise they're encoded with '+' character.UnsupportedEncodingException
- Thrown if URL encoding is not
applicable to objects of this type or
if encoding is unsuccessfulpublic static Object decode(Object pObject) throws UnsupportedEncodingException
pObject
- URL safe object to convert into its original formUnsupportedEncodingException
- Thrown if the argument is not a String
or byte[]
. Thrown if a failure condition is
encountered during the decode process.Copyright © 2002-2024 Atlassian. All Rights Reserved.