< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java

Print this page




  46 import java.util.Enumeration;
  47 import java.util.Iterator;
  48 import java.util.List;
  49 import java.util.NoSuchElementException;
  50 import java.util.Set;
  51 import java.util.jar.JarEntry;
  52 import java.util.jar.JarFile;
  53 import java.util.stream.Collectors;
  54 import java.util.stream.Stream;
  55 import java.util.zip.ZipFile;
  56 
  57 /**
  58  * ClassFileReader reads ClassFile(s) of a given path that can be
  59  * a .class file, a directory, or a JAR file.
  60  */
  61 public class ClassFileReader implements Closeable {
  62     /**
  63      * Returns a ClassFileReader instance of a given path.
  64      */
  65     public static ClassFileReader newInstance(Path path) throws IOException {
  66         return newInstance(path, JarFile.baseVersion());
  67     }
  68 
  69     /**
  70      * Returns a ClassFileReader instance of a given path.
  71      */
  72     public static ClassFileReader newInstance(Path path, Runtime.Version version) throws IOException {
  73         if (Files.notExists(path)) {
  74             throw new FileNotFoundException(path.toString());
  75         }
  76 
  77         if (Files.isDirectory(path)) {
  78             return new DirectoryReader(path);
  79         } else if (path.getFileName().toString().endsWith(".jar")) {
  80             return new JarFileReader(path, version);
  81         } else {
  82             return new ClassFileReader(path);
  83         }
  84     }
  85 
  86     /**




  46 import java.util.Enumeration;
  47 import java.util.Iterator;
  48 import java.util.List;
  49 import java.util.NoSuchElementException;
  50 import java.util.Set;
  51 import java.util.jar.JarEntry;
  52 import java.util.jar.JarFile;
  53 import java.util.stream.Collectors;
  54 import java.util.stream.Stream;
  55 import java.util.zip.ZipFile;
  56 
  57 /**
  58  * ClassFileReader reads ClassFile(s) of a given path that can be
  59  * a .class file, a directory, or a JAR file.
  60  */
  61 public class ClassFileReader implements Closeable {
  62     /**
  63      * Returns a ClassFileReader instance of a given path.
  64      */
  65     public static ClassFileReader newInstance(Path path) throws IOException {
  66         return newInstance(path, null);
  67     }
  68 
  69     /**
  70      * Returns a ClassFileReader instance of a given path.
  71      */
  72     public static ClassFileReader newInstance(Path path, Runtime.Version version) throws IOException {
  73         if (Files.notExists(path)) {
  74             throw new FileNotFoundException(path.toString());
  75         }
  76 
  77         if (Files.isDirectory(path)) {
  78             return new DirectoryReader(path);
  79         } else if (path.getFileName().toString().endsWith(".jar")) {
  80             return new JarFileReader(path, version);
  81         } else {
  82             return new ClassFileReader(path);
  83         }
  84     }
  85 
  86     /**


< prev index next >