langtools/src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ClassFileReader.java
changeset 42827 36468b5fa7f4
parent 42407 f3702cff2933
equal deleted inserted replaced
42826:563b42fc70ba 42827:36468b5fa7f4
   145         }
   145         }
   146         return null;
   146         return null;
   147     }
   147     }
   148 
   148 
   149     public Iterable<ClassFile> getClassFiles() throws IOException {
   149     public Iterable<ClassFile> getClassFiles() throws IOException {
   150         return new Iterable<ClassFile>() {
   150         return FileIterator::new;
   151             public Iterator<ClassFile> iterator() {
       
   152                 return new FileIterator();
       
   153             }
       
   154         };
       
   155     }
   151     }
   156 
   152 
   157     protected ClassFile readClassFile(Path p) throws IOException {
   153     protected ClassFile readClassFile(Path p) throws IOException {
   158         InputStream is = null;
   154         InputStream is = null;
   159         try {
   155         try {
   230         }
   226         }
   231 
   227 
   232         protected Set<String> scan() {
   228         protected Set<String> scan() {
   233             try (Stream<Path> stream = Files.walk(path, Integer.MAX_VALUE)) {
   229             try (Stream<Path> stream = Files.walk(path, Integer.MAX_VALUE)) {
   234                 return stream.filter(ClassFileReader::isClass)
   230                 return stream.filter(ClassFileReader::isClass)
   235                              .map(f -> path.relativize(f))
   231                              .map(path::relativize)
   236                              .map(Path::toString)
   232                              .map(Path::toString)
   237                              .map(p -> p.replace(File.separatorChar, '/'))
   233                              .map(p -> p.replace(File.separatorChar, '/'))
   238                              .collect(Collectors.toSet());
   234                              .collect(Collectors.toSet());
   239             } catch (IOException e) {
   235             } catch (IOException e) {
   240                 throw new UncheckedIOException(e);
   236                 throw new UncheckedIOException(e);
   262             return null;
   258             return null;
   263         }
   259         }
   264 
   260 
   265         public Iterable<ClassFile> getClassFiles() throws IOException {
   261         public Iterable<ClassFile> getClassFiles() throws IOException {
   266             final Iterator<ClassFile> iter = new DirectoryIterator();
   262             final Iterator<ClassFile> iter = new DirectoryIterator();
   267             return new Iterable<ClassFile>() {
   263             return () -> iter;
   268                 public Iterator<ClassFile> iterator() {
       
   269                     return iter;
       
   270                 }
       
   271             };
       
   272         }
   264         }
   273 
   265 
   274         class DirectoryIterator implements Iterator<ClassFile> {
   266         class DirectoryIterator implements Iterator<ClassFile> {
   275             private final List<Path> entries;
   267             private final List<Path> entries;
   276             private int index = 0;
   268             private int index = 0;
   385             }
   377             }
   386         }
   378         }
   387 
   379 
   388         public Iterable<ClassFile> getClassFiles() throws IOException {
   380         public Iterable<ClassFile> getClassFiles() throws IOException {
   389             final Iterator<ClassFile> iter = new JarFileIterator(this, jarfile);
   381             final Iterator<ClassFile> iter = new JarFileIterator(this, jarfile);
   390             return new Iterable<ClassFile>() {
   382             return () -> iter;
   391                 public Iterator<ClassFile> iterator() {
       
   392                     return iter;
       
   393                 }
       
   394             };
       
   395         }
   383         }
   396     }
   384     }
   397 
   385 
   398     Enumeration<JarEntry> versionedEntries(JarFile jf) {
   386     Enumeration<JarEntry> versionedEntries(JarFile jf) {
   399         Iterator<JarEntry> it = VersionedStream.stream(jf).iterator();
   387         Iterator<JarEntry> it = VersionedStream.stream(jf).iterator();