1 18 package org.apache.tools.ant.taskdefs.optional.depend; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.util.zip.ZipEntry ; 23 import java.util.zip.ZipInputStream ; 24 25 30 public class JarFileIterator implements ClassFileIterator { 31 32 private ZipInputStream jarStream; 33 34 40 public JarFileIterator(InputStream stream) throws IOException { 41 super(); 42 43 jarStream = new ZipInputStream (stream); 44 } 45 46 51 public ClassFile getNextClassFile() { 52 ZipEntry jarEntry; 53 ClassFile nextElement = null; 54 55 try { 56 jarEntry = jarStream.getNextEntry(); 57 58 while (nextElement == null && jarEntry != null) { 59 String entryName = jarEntry.getName(); 60 61 if (!jarEntry.isDirectory() && entryName.endsWith(".class")) { 62 63 ClassFile javaClass = new ClassFile(); 65 66 javaClass.read(jarStream); 67 68 nextElement = javaClass; 69 } else { 70 71 jarEntry = jarStream.getNextEntry(); 72 } 73 } 74 } catch (IOException e) { 75 String message = e.getMessage(); 76 String text = e.getClass().getName(); 77 78 if (message != null) { 79 text += ": " + message; 80 } 81 82 throw new RuntimeException ("Problem reading JAR file: " + text); 83 } 84 85 return nextElement; 86 } 87 88 } 89 90 | Popular Tags |