• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
URLCodec Class Reference
Inheritance diagram for URLCodec:
BinaryEncoder BinaryDecoder StringEncoder StringDecoder Encoder Decoder Encoder Decoder

Description

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 {Javadoc_link java.net.URLEncoder} and {Javadoc_link java.net.URLDecoder} on older Java platforms, as these classes in Java versions below 1.4 rely on the platform's default charset encoding.

Author
Apache Software Foundation
Since
1.2
Version
Id
URLCodec.java,v 1.19 2004/03/29 07:59:00 ggregory Exp

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

 URLCodec ()
 Default constructor.
 
 URLCodec (String charset)
 Constructor which allows for the selection of a default charset. More...
 
byte[] encode (byte[] bytes)
 Encodes an array of bytes into an array of URL safe 7-bit characters. More...
 
byte[] decode (byte[] bytes) throws DecoderException
 Decodes an array of URL safe 7-bit characters into an array of original bytes. More...
 
String encode (String pString, String charset) throws UnsupportedEncodingException
 Encodes a string into its URL safe form using the specified string charset. More...
 
String encode (String pString) throws EncoderException
 Encodes a string into its URL safe form using the default string charset. More...
 
String decode (String pString, String charset) throws DecoderException, UnsupportedEncodingException
 Decodes a URL safe string into its original form using the specified encoding. More...
 
String decode (String pString) throws DecoderException
 Decodes a URL safe string into its original form using the default string charset. More...
 
Object encode (Object pObject) throws EncoderException
 Encodes an object into its URL safe form. More...
 
Object decode (Object pObject) throws DecoderException
 Decodes a URL safe object into its original form. More...
 
String getEncoding ()
 The String encoding used for decoding and encoding. More...
 
String getDefaultCharset ()
 The default charset used for string decoding and encoding. More...
 

Static Public Member Functions

static final byte[] encodeUrl (BitSet urlsafe, byte[] bytes)
 Encodes an array of bytes into an array of URL safe 7-bit characters. More...
 
static final byte[] decodeUrl (byte[] bytes) throws DecoderException
 Decodes an array of URL safe 7-bit characters into an array of original bytes. More...
 

Protected Attributes

String charset = StringEncodings.UTF8
 The default charset used for string decoding and encoding.
 

Static Protected Attributes

static final BitSet WWW_FORM_URL = new BitSet(256)
 BitSet of www-form-url safe characters.
 

Constructor & Destructor Documentation

◆ URLCodec()

URLCodec ( String  charset)
Parameters
charsetthe default string charset to use.

Member Function Documentation

◆ encodeUrl()

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

Unsafe characters are escaped.

Parameters
urlsafebitset of characters deemed URL safe
bytesarray of bytes to convert to URL safe characters
Returns
array of bytes containing URL safe characters

◆ decodeUrl()

static final byte [] decodeUrl ( byte[]  bytes) throws DecoderException
static

Escaped characters are converted back to their original representation.

Parameters
bytesarray of URL safe characters
Returns
array of original bytes
Exceptions
DecoderExceptionThrown if URL decoding is unsuccessful

◆ encode() [1/4]

byte [] encode ( byte[]  bytes)

Unsafe characters are escaped.

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

Implements BinaryEncoder.

◆ decode() [1/4]

byte [] decode ( byte[]  bytes) throws DecoderException

Escaped characters are converted back to their original representation.

Parameters
bytesarray of URL safe characters
Returns
array of original bytes
Exceptions
DecoderExceptionThrown if URL decoding is unsuccessful

Implements BinaryDecoder.

◆ encode() [2/4]

String encode ( String  pString,
String  charset 
) throws UnsupportedEncodingException

Unsafe characters are escaped.

Parameters
pStringstring to convert to a URL safe form
charsetthe charset for pString
Returns
URL safe string
Exceptions
UnsupportedEncodingExceptionThrown if charset is not supported

◆ encode() [3/4]

String encode ( String  pString) throws EncoderException

Unsafe characters are escaped.

Parameters
pStringstring to convert to a URL safe form
Returns
URL safe string
Exceptions
EncoderExceptionThrown if URL encoding is unsuccessful
See also
getDefaultCharset()

Implements StringEncoder.

◆ decode() [2/4]

String decode ( String  pString,
String  charset 
) throws DecoderException, UnsupportedEncodingException

Escaped characters are converted back to their original representation.

Parameters
pStringURL safe string to convert into its original form
charsetthe original string charset
Returns
original string
Exceptions
DecoderExceptionThrown if URL decoding is unsuccessful
UnsupportedEncodingExceptionThrown if charset is not supported

◆ decode() [3/4]

String decode ( String  pString) throws DecoderException

Escaped characters are converted back to their original representation.

Parameters
pStringURL safe string to convert into its original form
Returns
original string
Exceptions
DecoderExceptionThrown if URL decoding is unsuccessful
See also
getDefaultCharset()

Implements StringDecoder.

◆ encode() [4/4]

Object encode ( Object  pObject) throws EncoderException

Unsafe characters are escaped.

Parameters
pObjectstring to convert to a URL safe form
Returns
URL safe object
Exceptions
EncoderExceptionThrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful

Implements Encoder.

◆ decode() [4/4]

Object decode ( Object  pObject) throws DecoderException

Escaped characters are converted back to their original representation.

Parameters
pObjectURL safe object to convert into its original form
Returns
original object
Exceptions
DecoderExceptionThrown if URL decoding is not applicable to objects of this type if decoding is unsuccessful

Implements Decoder.

◆ getEncoding()

String getEncoding ( )
Returns
Returns the encoding.
Deprecated:
use getDefaultCharset instead.

◆ getDefaultCharset()

String getDefaultCharset ( )
Returns
the default string charset.