Java URL Decode urlDecoder(String encoded)

Here you can find the source of urlDecoder(String encoded)

Description

url Decoder

License

Open Source License

Declaration

public static String urlDecoder(String encoded) 

Method Source Code

//package com.java2s;

public class Main {
    public static String urlDecoder(String encoded) {
        StringBuffer decoded = new StringBuffer();
        int len = encoded.length();
        for (int i = 0; i < len; ++i) {
            if (encoded.charAt(i) == '%' && i + 2 < len) {
                int d1 = Character.digit(encoded.charAt(i + 1), 16);
                int d2 = Character.digit(encoded.charAt(i + 2), 16);
                if (d1 != -1 && d2 != -1)
                    decoded.append((char) ((d1 << 4) + d2));
                i += 2;//from ww  w.ja  v a 2 s  .c o  m
            } else if (encoded.charAt(i) == '+')
                decoded.append(' ');
            else
                decoded.append(encoded.charAt(i));
        }
        return decoded.toString();
    }
}

Related

  1. urlDecode(String str)
  2. urlDecode(String text)
  3. urlDecodeBytes(String key)
  4. urlDecodeFilename(char[] input)
  5. urlDecodeInplace(StringBuilder input)
  6. xmlDecode(String s)