1 package org.scannotation.classpath;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.util.jar.JarEntry;
8 import java.util.jar.JarInputStream;
11 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
12 * @version $Revision: 1 $
14 public class JarIterator implements StreamIterator
19 boolean initial = true;
20 boolean closed = false;
22 public JarIterator(File file, Filter filter) throws IOException
24 this(new FileInputStream(file), filter);
28 public JarIterator(InputStream is, Filter filter) throws IOException
31 jar = new JarInputStream(is);
34 private void setNext()
39 if (next != null) jar.closeEntry();
43 next = jar.getNextJarEntry();
44 } while (next != null && (next.isDirectory() || (filter == null || !filter.accepts(next.getName()))));
52 throw new RuntimeException("failed to browse jar", e);
56 public InputStream next()
58 if (closed || (next == null && !initial)) return null;
60 if (next == null) return null;
61 return new InputStreamWrapper(jar);
71 catch (IOException ignored)