Java URI Encode encodeUri(String string)

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

Description

Encodes the given UTF-8 string so that it's safe for use within an URI.

License

Open Source License

Declaration

public static String encodeUri(String string) 

Method Source Code


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

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    /**/* w  w w  .  j av a  2  s . c  om*/
     * Encodes the given UTF-8 {@code string} so that it's safe for use
     * within an URI.
     */
    public static String encodeUri(String string) {
        if (string == null) {
            return null;
        }
        try {
            return URLEncoder.encode(string, "UTF-8").replace("+", "%20");
        } catch (UnsupportedEncodingException ex) {
            throw new IllegalStateException(ex);
        }
    }
}

Related

  1. encodeForURI(String uriPart)
  2. encodeIfNeeded(String uri)
  3. encodeUri(final String uri)
  4. encodeUri(final URI uri)
  5. encodeURI(String s)
  6. encodeURI(String uri)
  7. encodeUri(String uri)
  8. encodeUri(String uri)
  9. encodeUri(URI uri)