View Javadoc

1   package net.sf.jour.processor;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.Enumeration;
6   import java.util.jar.JarEntry;
7   import java.util.jar.JarFile;
8   
9   public class JarFileInputSource implements InputSource {
10  
11  	JarFile jarFile;
12  	
13  	public JarFileInputSource(File file) throws IOException {
14  		jarFile = new JarFile(file);
15  	}
16  	
17  	public void close() {
18  		try {
19  			jarFile.close();
20  		} catch (IOException ignore) {
21  		}
22  	}
23  
24  	
25  	public Enumeration getEntries() {
26  		return new JarEnumeration();
27  	}
28  
29  	private class JarEnumeration implements Enumeration {
30  
31  		Enumeration jarEnum;
32  		
33  		JarEnumeration() {
34  			jarEnum = jarFile.entries();
35  		}
36  		
37  		public boolean hasMoreElements() {
38  			return jarEnum.hasMoreElements();
39  		}
40  
41  		public Object nextElement() {
42  			JarEntry jarEntry = (JarEntry)jarEnum.nextElement();
43  			return new JarFileEntry(jarFile, jarEntry);
44  		}
45  		
46  	}
47  }