Java URL Decode urlDecode(String text)

Here you can find the source of urlDecode(String text)

Description

url Decode

License

Apache License

Declaration

public static String urlDecode(String text) 

Method Source Code

//package com.java2s;
/**/*from   w  ww.  jav  a  2 s.com*/
 * Copyright 2011 The Open Source Research Group,
 *                University of Erlangen-N?rnberg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static String urlDecode(String text) {
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < text.length(); ++i) {
            char ch = text.charAt(i);
            if (ch == '%' && i + 2 < text.length()) {
                String num = text.substring(i + 1, i + 3);
                try {
                    int val = Integer.valueOf(num, 16);
                    if (val >= 0x20 && val < 0x7F) {
                        ch = (char) val;
                        i += 2;
                    }
                } catch (NumberFormatException e) {
                }
            } else if (ch == '+') {
                ch = ' ';
            }

            b.append(ch);
        }
        return b.toString();
    }
}

Related

  1. urlDecode(String s)
  2. urlDecode(String scope)
  3. URLDecode(String str)
  4. urlDecode(String str)
  5. urldecode(String str)
  6. urlDecodeBytes(String key)
  7. urlDecodeFilename(char[] input)
  8. urlDecodeInplace(StringBuilder input)
  9. urlDecoder(String encoded)