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
61 Collection availableCharsets = Charset.availableCharsets().values();
62 Iterator iter = availableCharsets.iterator();
63 while (iter.hasNext()) {
64 charsets.remove(((Charset) iter.next()).getClass());
65 }
66
67 // remove the known pseudo-charsets that serve only to implement
68 // other charsets, but shouldn't be known to the public
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();
118 for (int i = 0; i < urls.length; i++) {
119 try {
120 URI uri = new URI(urls[i].toString());
121 classPathSegments.insertElementAt(uri.getPath(), 0);
122 } catch (URISyntaxException e) {
123 }
124 }
125
126 String[] classList = (String[])
127 java.security.AccessController.doPrivileged(
128 new java.security.PrivilegedAction() {
129 public Object run() {
130 return getClassList(packageName, "");
131 }
132 });
133
134 for (int i = 0; i < classList.length; i++) {
135 try {
|
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
49
50 public class NIOCharsetAvailabilityTest {
51
52 public static void main(String[] args) throws Exception {
53 // build the set of all Charset subclasses in the
54 // two known charset implementation packages
55 Set charsets = new HashSet();
56 addCharsets(charsets, "sun.nio.cs");
57 addCharsets(charsets, "sun.nio.cs.ext");
58
59 // remove the charsets that the API says are available
60 Collection availableCharsets = Charset.availableCharsets().values();
61 Iterator iter = availableCharsets.iterator();
62 while (iter.hasNext()) {
63 charsets.remove(((Charset) iter.next()).getClass());
64 }
65
66 // remove the known pseudo-charsets that serve only to implement
67 // other charsets, but shouldn't be known to the public
94 (PrivilegedAction<String>)() -> System.getProperty("sun.boot.class.path"));
95 String s = AccessController.doPrivileged(
96 (PrivilegedAction<String>)() -> System.getProperty("java.class.path"));
97
98 // Search combined system and application class path
99 if (s != null && s.length() != 0) {
100 classPath += File.pathSeparator + s;
101 }
102 while (classPath != null && classPath.length() != 0) {
103 int i = classPath.lastIndexOf(java.io.File.pathSeparatorChar);
104 String dir = classPath.substring(i + 1);
105 if (i == -1) {
106 classPath = null;
107 } else {
108 classPath = classPath.substring(0, i);
109 }
110 classPathSegments.insertElementAt(dir, 0);
111 }
112
113 // add extensions from the extension class loader
114 ClassLoader appLoader = ClassLoader.getSystemClassLoader();
115 URLClassLoader extLoader = (URLClassLoader) appLoader.getParent();
116 URL[] urls = extLoader.getURLs();
117 for (int i = 0; i < urls.length; i++) {
118 try {
119 URI uri = new URI(urls[i].toString());
120 classPathSegments.insertElementAt(uri.getPath(), 0);
121 } catch (URISyntaxException e) {
122 }
123 }
124
125 String[] classList = (String[])
126 java.security.AccessController.doPrivileged(
127 new java.security.PrivilegedAction() {
128 public Object run() {
129 return getClassList(packageName, "");
130 }
131 });
132
133 for (int i = 0; i < classList.length; i++) {
134 try {
|