Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/URLEncoder/Decoder.java
41149 views
1
/*
2
* Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 4407610
27
* @summary java.net.URLDecode.decode(st,"UTF-16") works incorrectly on '+' sign
28
*/
29
30
import java.net.*;
31
32
public class Decoder {
33
34
public static void main(String args[]) throws Exception {
35
36
boolean passed = true;
37
String enc = "UTF-16";
38
String strings[] = {
39
"\u0100\u0101",
40
"\u0100 \u0101",
41
"\u0100 \u0101\u0102",
42
"\u0100 \u0101 \u0102",
43
"\u0100C\u0101 \u0102",
44
"\u0100\u0101\u0102",
45
"?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&?&",
46
"foobar",
47
"foo?bar"
48
};
49
50
for (int i = 0; i < strings.length; i++) {
51
String encoded = URLEncoder.encode(strings[i], enc);
52
System.out.println("ecnoded: " + encoded);
53
String decoded = URLDecoder.decode(encoded, enc);
54
System.out.print("init: ");
55
printString(strings[i]);
56
System.out.print("decoded: ");
57
printString(decoded);
58
if (strings[i].equals(decoded)) {
59
System.out.println(" - correct - \n");
60
} else {
61
System.out.println(" - incorrect - \n");
62
throw new RuntimeException ("Unexpected decoded output on string " + i);
63
}
64
}
65
}
66
67
static void printString(String s) {
68
for (int i = 0; i < s.length(); i++) {
69
System.out.print((int)s.charAt(i) + " ");
70
}
71
System.out.println();
72
}
73
}
74
75