Java URI Encode encodeUriComponent(String value)

Here you can find the source of encodeUriComponent(String value)

Description

encode Uri Component

License

Open Source License

Declaration

public static String encodeUriComponent(String value) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main {
    public static String encodeUriComponent(String value) {
        try {/*from   w w  w  . ja va 2  s.c om*/
            return convertToGAStyleEncoding(URLEncoder.encode(value, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    public static String convertToGAStyleEncoding(String urlEncodedString) {
        return urlEncodedString.replace("+", "%20").replace("%21", "!").replace("%2A", "*").replace("%27", "'")
                .replace("%28", "(").replace("%29", ")");
    }
}

Related

  1. encodeURIComponent(final String s)
  2. encodeURIComponent(String component)
  3. encodeURIComponent(String input)
  4. encodeURIComponent(String s, String charset)
  5. encodeURIComponent(String uriComp)
  6. encodeURIComponentForJavaScript(String str)
  7. encodeURIParam(String s)
  8. encodeURIString(Writer out, String text, String encoding, int start)
  9. encodeUriWithPrefix(String uri)