public class URLCodec extends 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 immutable and thread-safe.
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
charset
已过时。
TODO: This field will be changed to a private final Charset in 2.0.
|
protected static byte |
ESCAPE_CHAR
Release 1.5 made this field final.
|
protected static BitSet |
WWW_FORM_URL
BitSet of www-form-url safe characters.
|
| 构造器和说明 |
|---|
URLCodec()
Default constructor.
|
URLCodec(String charset)
Constructor which allows for the selection of a default charset.
|
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
decode(byte[] bytes)
Decodes an array of URL safe 7-bit characters into an array of original bytes.
|
Object |
decode(Object obj)
Decodes a URL safe object into its original form.
|
String |
decode(String str)
Decodes a URL safe string into its original form using the default string charset.
|
String |
decode(String str,
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.
|
byte[] |
encode(byte[] bytes)
Encodes an array of bytes into an array of URL safe 7-bit characters.
|
Object |
encode(Object obj)
Encodes an object into its URL safe form.
|
String |
encode(String str)
Encodes a string into its URL safe form using the default string charset.
|
String |
encode(String str,
String charset)
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.
|
String |
getDefaultCharset()
The default charset used for string decoding and encoding.
|
String |
getEncoding()
已过时。
Use
getDefaultCharset(), will be removed in 2.0. |
@Deprecated protected String charset
protected static final byte ESCAPE_CHAR
protected static final BitSet WWW_FORM_URL
public URLCodec()
public URLCodec(String charset)
charset - the default string charset to use.public static final byte[] encodeUrl(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 在接口中 BinaryEncoderbytes - array of bytes to convert to URL safe characterspublic byte[] decode(byte[] bytes)
throws DecoderException
decode 在接口中 BinaryDecoderbytes - array of URL safe charactersDecoderException - Thrown if URL decoding is unsuccessfulpublic String encode(String str, String charset) throws UnsupportedEncodingException
str - string to convert to a URL safe formcharset - the charset for strUnsupportedEncodingException - Thrown if charset is not supportedpublic String encode(String str) throws EncoderException
encode 在接口中 StringEncoderstr - string to convert to a URL safe formEncoderException - Thrown if URL encoding is unsuccessfulgetDefaultCharset()public String decode(String str, String charset) throws DecoderException, UnsupportedEncodingException
str - URL safe string to convert into its original formcharset - the original string charsetDecoderException - Thrown if URL decoding is unsuccessfulUnsupportedEncodingException - Thrown if charset is not supportedpublic String decode(String str) throws DecoderException
decode 在接口中 StringDecoderstr - URL safe string to convert into its original formDecoderException - Thrown if URL decoding is unsuccessfulgetDefaultCharset()public Object encode(Object obj) throws EncoderException
encode 在接口中 Encoderobj - 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 Object decode(Object obj) throws DecoderException
decode 在接口中 Decoderobj - 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 String getDefaultCharset()
@Deprecated public String getEncoding()
getDefaultCharset(), will be removed in 2.0.String encoding used for decoding and encoding.Copyright © 2017. All rights reserved.