equal
deleted
inserted
replaced
28 import com.sun.tools.classfile.AccessFlags; |
28 import com.sun.tools.classfile.AccessFlags; |
29 import com.sun.tools.classfile.ClassFile; |
29 import com.sun.tools.classfile.ClassFile; |
30 import com.sun.tools.classfile.ConstantPoolException; |
30 import com.sun.tools.classfile.ConstantPoolException; |
31 import com.sun.tools.classfile.Dependencies.ClassFileError; |
31 import com.sun.tools.classfile.Dependencies.ClassFileError; |
32 |
32 |
33 import jdk.internal.util.jar.VersionedStream; |
|
34 |
|
35 import java.io.Closeable; |
33 import java.io.Closeable; |
36 import java.io.File; |
34 import java.io.File; |
37 import java.io.FileNotFoundException; |
35 import java.io.FileNotFoundException; |
38 import java.io.IOException; |
36 import java.io.IOException; |
39 import java.io.InputStream; |
37 import java.io.InputStream; |
334 return jf; |
332 return jf; |
335 } |
333 } |
336 |
334 |
337 protected Set<String> scan() { |
335 protected Set<String> scan() { |
338 try (JarFile jf = openJarFile(path.toFile(), version)) { |
336 try (JarFile jf = openJarFile(path.toFile(), version)) { |
339 return VersionedStream.stream(jf).map(JarEntry::getName) |
337 return jf.versionedStream().map(JarEntry::getName) |
340 .filter(n -> n.endsWith(".class")) |
338 .filter(n -> n.endsWith(".class")) |
341 .collect(Collectors.toSet()); |
339 .collect(Collectors.toSet()); |
342 } catch (IOException e) { |
340 } catch (IOException e) { |
343 throw new UncheckedIOException(e); |
341 throw new UncheckedIOException(e); |
344 } |
342 } |
381 final Iterator<ClassFile> iter = new JarFileIterator(this, jarfile); |
379 final Iterator<ClassFile> iter = new JarFileIterator(this, jarfile); |
382 return () -> iter; |
380 return () -> iter; |
383 } |
381 } |
384 } |
382 } |
385 |
383 |
386 Enumeration<JarEntry> versionedEntries(JarFile jf) { |
|
387 Iterator<JarEntry> it = VersionedStream.stream(jf).iterator(); |
|
388 return new Enumeration<>() { |
|
389 @Override |
|
390 public boolean hasMoreElements() { |
|
391 return it.hasNext(); |
|
392 } |
|
393 |
|
394 @Override |
|
395 public JarEntry nextElement() { |
|
396 return it.next(); |
|
397 } |
|
398 }; |
|
399 } |
|
400 |
|
401 class JarFileIterator implements Iterator<ClassFile> { |
384 class JarFileIterator implements Iterator<ClassFile> { |
402 protected final JarFileReader reader; |
385 protected final JarFileReader reader; |
403 protected Enumeration<JarEntry> entries; |
386 protected Iterator<JarEntry> entries; |
404 protected JarFile jf; |
387 protected JarFile jf; |
405 protected JarEntry nextEntry; |
388 protected JarEntry nextEntry; |
406 protected ClassFile cf; |
389 protected ClassFile cf; |
407 JarFileIterator(JarFileReader reader) { |
390 JarFileIterator(JarFileReader reader) { |
408 this(reader, null); |
391 this(reader, null); |
414 |
397 |
415 void setJarFile(JarFile jarfile) { |
398 void setJarFile(JarFile jarfile) { |
416 if (jarfile == null) return; |
399 if (jarfile == null) return; |
417 |
400 |
418 this.jf = jarfile; |
401 this.jf = jarfile; |
419 this.entries = versionedEntries(jf); |
402 this.entries = jarfile.versionedStream().iterator(); |
420 this.nextEntry = nextEntry(); |
403 this.nextEntry = nextEntry(); |
421 } |
404 } |
422 |
405 |
423 public boolean hasNext() { |
406 public boolean hasNext() { |
424 if (nextEntry != null && cf != null) { |
407 if (nextEntry != null && cf != null) { |
448 nextEntry = nextEntry(); |
431 nextEntry = nextEntry(); |
449 return classFile; |
432 return classFile; |
450 } |
433 } |
451 |
434 |
452 protected JarEntry nextEntry() { |
435 protected JarEntry nextEntry() { |
453 while (entries.hasMoreElements()) { |
436 while (entries.hasNext()) { |
454 JarEntry e = entries.nextElement(); |
437 JarEntry e = entries.next(); |
455 String name = e.getName(); |
438 String name = e.getName(); |
456 if (name.endsWith(".class")) { |
439 if (name.endsWith(".class")) { |
457 return e; |
440 return e; |
458 } |
441 } |
459 } |
442 } |