public final class UrlEncoder extends Object
In contrast to the URLEncoder
, this class does not encode
' ' (space) space as '+' (plus)!
Additionally, this class does not use the default encoding, but always UTF-8, if not specified otherwise.
The reason for this class is that File.toURI()
does not encode a "+" sign. Therefore, our URL-encoding and decoding must
not handle the "+" specifically.
Another reason is JERSEY-417.
I originally used org.glassfish.jersey.uri.UriComponent.encode(String, Type)
at some code locations, but since not all code locations have a dependency on Jersey,
I decided to switch consistently everywhere to UrlEncoder
and UrlDecoder
.
This class was copied from URLEncoder
and changed to fit our needs.
UrlDecoder
Modifier and Type | Method and Description |
---|---|
static String |
encode(String s)
Translates a string into
application/x-www-form-urlencoded
format using UTF-8. |
static String |
encode(String s,
Charset charset)
Deprecated.
UTF-8 should be used; it is thus recommended to invoke
encode(String) instead. |
static String |
encode(String s,
String enc)
Deprecated.
UTF-8 should be used; it is thus recommended to invoke
encode(String) instead. |
public static String encode(String s)
application/x-www-form-urlencoded
format using UTF-8.s
- String
to be translated.@Deprecated public static String encode(String s, String enc) throws UnsupportedEncodingException
encode(String)
instead.application/x-www-form-urlencoded
format using a specific encoding scheme. This method uses the
supplied encoding scheme to obtain the bytes for unsafe
characters.
Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.
s
- String
to be translated.enc
- The name of a supported
character
encoding.String
.UnsupportedEncodingException
- If the named encoding is not supportedUrlDecoder.decode(String, String)
@Deprecated public static String encode(String s, Charset charset)
encode(String)
instead.application/x-www-form-urlencoded
format using a specific encoding scheme. This method uses the
supplied encoding scheme to obtain the bytes for unsafe
characters.
Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities.
s
- String
to be translated.charset
- The character encoding.String
.UnsupportedEncodingException
- If the named encoding is not supportedUrlDecoder.decode(String, Charset)
Copyright © 2013–2019. All rights reserved.