Java URI Decode decodeToUtf8(String uri)

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

Description

Decodes uri replacing '+' with ' ' and percent encoded characters with their utf equivalents.

License

Open Source License

Return

copy of original uri if there no characters had to be decoded

Declaration

public static String decodeToUtf8(String uri) throws URISyntaxException 

Method Source Code


//package com.java2s;
import java.io.UnsupportedEncodingException;

import java.net.URISyntaxException;
import java.net.URLDecoder;

public class Main {
    /**/*ww  w.j  a  va  2 s  .  c om*/
     * Decodes <code>uri</code> replacing '+' with ' ' and percent encoded characters
     * with their utf equivalents.
     * 
     * @return copy of original uri if there no characters had to be decoded
     */
    public static String decodeToUtf8(String uri) throws URISyntaxException {
        try {
            return URLDecoder.decode(uri, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException iae) {
            throw new URISyntaxException(uri, "invalid url");
        }
    }
}

Related

  1. decode(String encodedURI)
  2. decode(String uri)
  3. decodeUnreserved(URI address)
  4. decodeURI(CharSequence uriCharSequence, String charset)
  5. decodeURI(java.net.URI uri)
  6. decodeURI(String s)