Java URI Encode encodeUri(String uri)

Here you can find the source of encodeUri(String uri)

Description

encode Uri

License

Open Source License

Declaration

public static String encodeUri(String uri) 

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 encodeUri(String uri) {
        int quoIndex = uri.indexOf("?");
        if (quoIndex < 0 || quoIndex == uri.length()) {
            return uri;
        }/*from  w  w  w. jav a  2s.  c o  m*/
        String url = uri.substring(0, quoIndex);
        String param = uri.substring(quoIndex + 1);
        String encodedUri = uri;
        try {
            encodedUri = url + "?" + URLEncoder.encode(param, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encodedUri;
    }
}

Related

  1. encodeUri(final URI uri)
  2. encodeURI(String s)
  3. encodeUri(String string)
  4. encodeURI(String uri)
  5. encodeUri(String uri)
  6. encodeUri(URI uri)
  7. encodeURI(URI uri)
  8. encodeURIComponent(final String s)
  9. encodeURIComponent(String component)