Java Utililty Methods URI Encode

List of utility methods to do URI Encode

Description

The list of methods to do URI Encode are organized into topic(s).

Method

StringencodeURIParam(String s)
encode URI Param
String ret = null;
try {
    ret = URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
    throw e;
return ret;
voidencodeURIString(Writer out, String text, String encoding, int start)
encode URI String
ByteArrayOutputStream buf = null;
OutputStreamWriter writer = null;
char[] charArray = null;
int length = text.length();
for (int i = start; i < length; i++) {
    char ch = text.charAt(i);
    if (DONT_ENCODE_SET.get(ch)) {
        out.write(ch);
...
StringencodeUriWithPrefix(String uri)
Elements (identifiers) used in MDX need to follow certain rules in order to be parseable from and to MDX.
return encodeSpecialMdxCharactersInNames(uri);
StringuriEncode(Object o)
uri Encode
try {
    assert (o != null) : "o canot be null";
    return URLEncoder.encode(o.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("UTF-8 is not supported by this system?", e);
StringuriEncode(String decoded)
uri Encode
return URLEncoder.encode(decoded, "UTF-8");
StringuriEncode(String input)
uri Encode
return URLEncoder.encode(input, "UTF-8").replace("+", "%20");
StringuriEncodePath(String path)
uri Encode Path
try {
    URI uri = new URI(null, null, path, null);
    return uri.toASCIIString();
} catch (URISyntaxException e) {
    throw new IllegalArgumentException(String.format("uriEncode failed, path=\"%s\".", path), e);
StringuriEncoding(String plainString)
uri Encoding
try {
    URL url = new URL(plainString);
    URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
            url.getQuery(), url.getRef());
    return uri.toString();
} catch (URISyntaxException | MalformedURLException e) {
    System.out.println("Utilities.uriEncoding(String plainString)\nError trying to encode " + plainString);
    return null;
...