1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.net;
19
20import java.io.UnsupportedEncodingException;
21import java.nio.charset.Charset;
22import libcore.net.UriCodec;
23
24/**
25 * This class is used to decode a string which is encoded in the {@code
26 * application/x-www-form-urlencoded} MIME content type.
27 */
28public class URLDecoder {
29    /**
30     * Decodes the argument which is assumed to be encoded in the {@code
31     * x-www-form-urlencoded} MIME content type.
32     * <p>
33     *'+' will be converted to space, '%' and two following hex digit
34     * characters are converted to the equivalent byte value. All other
35     * characters are passed through unmodified. For example "A+B+C %24%25" ->
36     * "A B C $%".
37     *
38     * @param s
39     *            the encoded string.
40     * @return the decoded clear-text representation of the given string.
41     * @deprecated Use {@link #decode(String, String)} instead.
42     */
43    @Deprecated
44    public static String decode(String s) {
45        return UriCodec.decode(s, true, Charset.defaultCharset(), true);
46    }
47
48    /**
49     * Decodes the argument which is assumed to be encoded in the {@code
50     * x-www-form-urlencoded} MIME content type, assuming the given {@code charsetName}.
51     *
52     *'<p>+' will be converted to space, '%' and two following hex digit
53     * characters are converted to the equivalent byte value. All other
54     * characters are passed through unmodified. For example "A+B+C %24%25" ->
55     * "A B C $%".
56     *
57     * @throws UnsupportedEncodingException if {@code charsetName} is not supported.
58     */
59    public static String decode(String s, String charsetName) throws UnsupportedEncodingException {
60        return UriCodec.decode(s, true, Charset.forName(charsetName), true);
61    }
62}
63