Java URL Decode decode(String str)

Here you can find the source of decode(String str)

Description

Decodes URL octets except %2f (i.e.

License

Apache License

Parameter

Parameter Description
str string to encode

Return

encoded string

Declaration

static String decode(String str) throws UnsupportedEncodingException 

Method Source Code


//package com.java2s;
/* See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Esri Inc. licenses this file to You 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.// w  ww  . j a  v a2 s  .co m
 */

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

public class Main {
    /**
     * Decodes URL octets except %2f (i.e. / character)
     * @param str string to encode
     * @return encoded string
     */
    /*package*/ static String decode(String str) throws UnsupportedEncodingException {
        if (str != null) {
            StringBuilder sb = new StringBuilder();
            for (int idx = str.toLowerCase().indexOf("%2f"); idx >= 0; idx = str.toLowerCase().indexOf("%2f")) {
                sb.append(URLDecoder.decode(str.substring(0, idx), "UTF-8")).append(str.substring(idx, idx + 3));
                str = str.substring(idx + 3);
            }
            sb.append(URLDecoder.decode(str, "UTF-8"));
            str = sb.toString();
        }
        return str;
    }
}

Related

  1. decode(String s, String enc)
  2. decode(String source)
  3. decode(String source, String encoding)
  4. decode(String source, String encoding)
  5. decode(String str)
  6. decode(String value)
  7. decode(String value)
  8. decode(String value)
  9. decode(String value)