Top Description Constructors Methods
java.net

public Class URLDecoder

extends Object
Class Inheritance
Imports
java.io.*, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, java.util.Objects

Utility class for HTML form decoding. This class contains static methods for decoding a String from the application/x-www-form-urlencoded MIME format.

The conversion process is the reverse of that used by the URLEncoder class. It is assumed that all characters in the encoded string are one of the following: "a" through "z", "A" through "Z", "0" through "9", and "-", "_", ".", and "*". The character "%" is allowed but is interpreted as the start of a special escaped sequence.

The following rules are applied in the conversion:

There are two possible ways in which this decoder could deal with illegal strings. It could either leave illegal characters alone or it could throw an java.lang.IllegalArgumentException. Which approach the decoder takes is left to the implementation.

Authors
Mark Chamness, Michael McCloskey
Since
1.2
See Also
Charset#defaultCharset()

Constructor Summary

AccessConstructor and Description
private
URLDecoder()

Do not call.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the newly decoded String
decode
(String
the String to decode
s
)
Deprecated The resulting string may vary depending on the default charset. Instead, use the decode(String,String) method to specify the encoding.

Decodes a x-www-form-urlencoded string.

public static String

Returns:

the newly decoded String
decode
(String
the String to decode
s
,
String
The name of a supported character encoding.
enc
)

Decodes an application/x-www-form-urlencoded string using a specific encoding scheme.

public static String

Returns:

the newly decoded String
decode
(String
the String to decode
s
,
Charset
the given charset
charset
)

Decodes an application/x-www-form-urlencoded string using a specific Charset.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

URLDecoderback to summary
private URLDecoder()

Do not call.

Method Detail

decodeback to summary
public static String decode(String s)

Deprecated

The resulting string may vary depending on the default charset. Instead, use the decode(String,String) method to specify the encoding.

Decodes a x-www-form-urlencoded string. The default charset is used to determine what characters are represented by any consecutive sequences of the form "%xy".

Parameters
s:String

the String to decode

Returns:String

the newly decoded String

Annotations
@Deprecated
Exceptions
IllegalArgumentException:
if the implementation encounters malformed escape sequences
decodeback to summary
public static String decode(String s, String enc) throws UnsupportedEncodingException

Decodes an application/x-www-form-urlencoded string using a specific encoding scheme.

This method behaves the same as decode(String s, Charset charset) except that it will look up the charset using the given encoding name.

Parameters
s:String

the String to decode

enc:String

The name of a supported character encoding.

Returns:String

the newly decoded String

Exceptions
UnsupportedEncodingException:
If character encoding needs to be consulted, but named character encoding is not supported
IllegalArgumentException:
if the implementation encounters malformed escape sequences
Since
1.4
See Also
URLEncoder#encode(java.lang.String, java.lang.String)
decodeback to summary
public static String decode(String s, Charset charset)

Decodes an application/x-www-form-urlencoded string using a specific Charset. The supplied charset is used to determine what characters are represented by any consecutive escape sequences of the form "%xy". Erroneous bytes are replaced with the supplied Charset's replacement value.

Note

The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.

Parameters
s:String

the String to decode

charset:Charset

the given charset

Returns:String

the newly decoded String

Exceptions
NullPointerException:
if s or charset is null
IllegalArgumentException:
if the implementation encounters malformed escape sequences
Since
10
External Specification
https://www.w3.org/TR/html4
See Also
URLEncoder#encode(java.lang.String, Charset)