1 /*
2 * Copyright (c) 2010, 2012, 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 4777124 6920545 6911753
27 * @summary Verify that all Charset subclasses are available through the API
28 */
29
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.FileNotFoundException;
33 import java.io.IOException;
34 import java.net.URI;
35 import java.net.URISyntaxException;
36 import java.net.URL;
37 import java.net.URLClassLoader;
38 import java.nio.charset.Charset;
39 import java.util.Collection;
40 import java.util.HashSet;
41 import java.util.Iterator;
42 import java.util.Set;
43 import java.util.Vector;
44 import java.util.zip.ZipEntry;
45 import java.util.zip.ZipInputStream;
46 import sun.misc.Launcher;
47
48
49 public class NIOCharsetAvailabilityTest {
50
51 public static void main(String[] args) throws Exception {
52 // build the set of all Charset subclasses in the
53 // two known charset implementation packages
54 Set charsets = new HashSet();
55 addCharsets(charsets, "sun.nio.cs");
56 addCharsets(charsets, "sun.nio.cs.ext");
57
58 // remove the charsets that the API says are available
72 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_MS932"));
73 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0212_MS5022X"));
74 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0212_Solaris"));
75 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_MS5022X"));
76
77 // report the charsets that are implemented but not available
78 iter = charsets.iterator();
79 while (iter.hasNext()) {
80 System.out.println("Unused Charset subclass: " + ((Class) iter.next()).getName());
81 }
82 if (charsets.size() > 0) {
83 throw new RuntimeException();
84 }
85 }
86
87 private static Vector classPathSegments = new Vector();
88
89 private static void addCharsets(Set charsets, final String packageName)
90 throws Exception {
91
92 String classPath =
93 (String) java.security.AccessController.doPrivileged(
94 new sun.security.action.GetPropertyAction("sun.boot.class.path"));
95 String s =
96 (String) java.security.AccessController.doPrivileged(
97 new sun.security.action.GetPropertyAction("java.class.path"));
98
99 // Search combined system and application class path
100 if (s != null && s.length() != 0) {
101 classPath += File.pathSeparator + s;
102 }
103 while (classPath != null && classPath.length() != 0) {
104 int i = classPath.lastIndexOf(java.io.File.pathSeparatorChar);
105 String dir = classPath.substring(i + 1);
106 if (i == -1) {
107 classPath = null;
108 } else {
109 classPath = classPath.substring(0, i);
110 }
111 classPathSegments.insertElementAt(dir, 0);
112 }
113
114 // add extensions from the extension class loader
115 ClassLoader appLoader = Launcher.getLauncher().getClassLoader();
116 URLClassLoader extLoader = (URLClassLoader) appLoader.getParent();
117 URL[] urls = extLoader.getURLs();
|
1 /*
2 * Copyright (c) 2010, 2014, 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 4777124 6920545 6911753
27 * @summary Verify that all Charset subclasses are available through the API
28 */
29
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.FileNotFoundException;
33 import java.io.IOException;
34 import java.net.URI;
35 import java.net.URISyntaxException;
36 import java.net.URL;
37 import java.net.URLClassLoader;
38 import java.nio.charset.Charset;
39 import java.security.AccessController;
40 import java.security.PrivilegedAction;
41 import java.util.Collection;
42 import java.util.HashSet;
43 import java.util.Iterator;
44 import java.util.Set;
45 import java.util.Vector;
46 import java.util.zip.ZipEntry;
47 import java.util.zip.ZipInputStream;
48 import sun.misc.Launcher;
49
50
51 public class NIOCharsetAvailabilityTest {
52
53 public static void main(String[] args) throws Exception {
54 // build the set of all Charset subclasses in the
55 // two known charset implementation packages
56 Set charsets = new HashSet();
57 addCharsets(charsets, "sun.nio.cs");
58 addCharsets(charsets, "sun.nio.cs.ext");
59
60 // remove the charsets that the API says are available
74 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_MS932"));
75 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0212_MS5022X"));
76 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0212_Solaris"));
77 charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_MS5022X"));
78
79 // report the charsets that are implemented but not available
80 iter = charsets.iterator();
81 while (iter.hasNext()) {
82 System.out.println("Unused Charset subclass: " + ((Class) iter.next()).getName());
83 }
84 if (charsets.size() > 0) {
85 throw new RuntimeException();
86 }
87 }
88
89 private static Vector classPathSegments = new Vector();
90
91 private static void addCharsets(Set charsets, final String packageName)
92 throws Exception {
93
94 String classPath = AccessController.doPrivileged(
95 (PrivilegedAction<String>)() -> System.getProperty("sun.boot.class.path"));
96 String s = AccessController.doPrivileged(
97 (PrivilegedAction<String>)() -> System.getProperty("java.class.path"));
98
99 // Search combined system and application class path
100 if (s != null && s.length() != 0) {
101 classPath += File.pathSeparator + s;
102 }
103 while (classPath != null && classPath.length() != 0) {
104 int i = classPath.lastIndexOf(java.io.File.pathSeparatorChar);
105 String dir = classPath.substring(i + 1);
106 if (i == -1) {
107 classPath = null;
108 } else {
109 classPath = classPath.substring(0, i);
110 }
111 classPathSegments.insertElementAt(dir, 0);
112 }
113
114 // add extensions from the extension class loader
115 ClassLoader appLoader = Launcher.getLauncher().getClassLoader();
116 URLClassLoader extLoader = (URLClassLoader) appLoader.getParent();
117 URL[] urls = extLoader.getURLs();
|