package org.test4j.junit.filter.iterator; import java.io.*; import java.util.*; import java.util.jar.*; /** * This class provides an iterator over all file names in a jar file. * Directories are not considered to be files. */ public class JarFileIterator implements Iterator<String>, Iterable<String> { private Enumeration<JarEntry> entries; private JarEntry next; public JarFileIterator(File jarFile) throws IOException { JarFile jar = new JarFile(jarFile); entries = jar.entries(); retrieveNextElement(); } private void retrieveNextElement() { next = null; while (entries.hasMoreElements()) { next = entries.nextElement(); if (!next.isDirectory()) { break; } } } public boolean hasNext() { return next != null; } public String next() { if (next == null) { throw new NoSuchElementException(); } String value = next.getName(); retrieveNextElement(); return value; } public void remove() { throw new RuntimeException("Not implemented"); } public Iterator<String> iterator() { return this; } }