Here you can find the source of decodeURI(URI uri)
Parameter | Description |
---|---|
uri | The URI to decode. |
public static String decodeURI(URI uri)
//package com.java2s; import java.net.URI; public class Main { /**//from w w w. ja va 2 s .com * Decode a URI by converting all percent encoded character into a String * character. * * @param uri * The URI to decode. * @return The specified URI in a String with converted percent encoded * characters. */ public static String decodeURI(URI uri) { StringBuffer retVal = new StringBuffer(); String uriStr = uri.toASCIIString(); char c; for (int i = 0; i < uriStr.length(); ++i) { c = uriStr.charAt(i); if (c == '%') { // We certainly found an encoded character, check for length // now ( '%' HEXDIGIT HEXDIGIT) if (((uriStr.length() - i) < 2)) { throw new IllegalArgumentException( "The uri " + uriStr + " contain invalid encoded character !"); } // Decode the encoded character char decodedChar = (char) Integer.parseInt(uriStr.substring(i + 1, i + 3), 16); retVal.append(decodedChar); i += 2; continue; } retVal.append(c); } return retVal.toString(); } }