< prev index next >

test/java/nio/charset/Charset/NIOCharsetAvailabilityTest.java

Print this page




  29 
  30 import java.net.URI;
  31 import java.nio.charset.Charset;
  32 import java.nio.file.FileSystem;
  33 import java.nio.file.FileSystems;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.util.HashSet;
  37 import java.util.Set;
  38 import java.util.stream.Collectors;
  39 import java.util.stream.Stream;
  40 
  41 public class NIOCharsetAvailabilityTest {
  42 
  43     public static void main(String[] args) throws Exception {
  44 
  45         // build the set of all Charset subclasses in the
  46         // two known charset implementation packages
  47         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
  48         Set<Class> charsets =
  49             Stream.concat(Files.walk(fs.getPath("/java.base/sun/nio/cs/")),
  50                           Files.walk(fs.getPath("/jdk.charsets/sun/nio/cs/ext/")))
  51                  .map( p -> p.subpath(1, p.getNameCount()).toString())
  52                  .filter( s ->  s.indexOf("$") == -1 && s.endsWith(".class"))
  53                  .map( s -> {
  54                      try {
  55                          return Class.forName(s.substring(0, s.length() - 6)
  56                                                .replace('/', '.'));
  57                      } catch (Exception x) {
  58                          throw new RuntimeException(x);
  59                      }
  60                   })
  61                  .filter( clz -> {
  62                      Class superclazz = clz.getSuperclass();
  63                      while (superclazz != null && !superclazz.equals(Object.class)) {
  64                          if (superclazz.equals(Charset.class)) {
  65                              return true;
  66                          } else {
  67                              superclazz = superclazz.getSuperclass();
  68                          }
  69                      }
  70                      return false;
  71                   })




  29 
  30 import java.net.URI;
  31 import java.nio.charset.Charset;
  32 import java.nio.file.FileSystem;
  33 import java.nio.file.FileSystems;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.util.HashSet;
  37 import java.util.Set;
  38 import java.util.stream.Collectors;
  39 import java.util.stream.Stream;
  40 
  41 public class NIOCharsetAvailabilityTest {
  42 
  43     public static void main(String[] args) throws Exception {
  44 
  45         // build the set of all Charset subclasses in the
  46         // two known charset implementation packages
  47         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
  48         Set<Class> charsets =
  49             Stream.concat(Files.walk(fs.getPath("/modules/java.base/sun/nio/cs/")),
  50                           Files.walk(fs.getPath("/modules/jdk.charsets/sun/nio/cs/ext/")))
  51                  .map( p -> p.subpath(2, p.getNameCount()).toString())
  52                  .filter( s ->  s.indexOf("$") == -1 && s.endsWith(".class"))
  53                  .map( s -> {
  54                      try {
  55                          return Class.forName(s.substring(0, s.length() - 6)
  56                                                .replace('/', '.'));
  57                      } catch (Exception x) {
  58                          throw new RuntimeException(x);
  59                      }
  60                   })
  61                  .filter( clz -> {
  62                      Class superclazz = clz.getSuperclass();
  63                      while (superclazz != null && !superclazz.equals(Object.class)) {
  64                          if (superclazz.equals(Charset.class)) {
  65                              return true;
  66                          } else {
  67                              superclazz = superclazz.getSuperclass();
  68                          }
  69                      }
  70                      return false;
  71                   })


< prev index next >