1 package com.quadcap.io.dir; 2 3 40 41 import java.io.File ; 42 import java.io.IOException ; 43 44 import java.util.Enumeration ; 45 46 import java.util.jar.JarFile ; 47 48 import java.net.MalformedURLException ; 49 import java.net.URL ; 50 51 56 57 public class JarDirectory extends Directory { 58 URL base; 59 JarFile jar; 60 File file; 61 62 public JarDirectory(File f) throws IOException { 63 this.file = f; 64 this.jar = new JarFile (f); 65 this.base = new URL ("jar:file:" + f.getAbsolutePath() + "!/"); 66 } 67 68 public Enumeration entries() { 69 final JarDirectory dir = this; 70 final Enumeration je = jar.entries(); 71 return new Enumeration () { 72 public boolean hasMoreElements() { 73 return je.hasMoreElements(); 74 } 75 public Object nextElement() { 76 java.util.jar.JarEntry j = (java.util.jar.JarEntry )je.nextElement(); 77 return j.getName(); 78 } 79 }; 80 } 81 82 public Entry getEntry(String name) { 83 java.util.jar.JarEntry j = jar.getJarEntry(name); 84 if (j != null) { 85 return new JarEntry(this, j); 86 } else { 87 return null; 88 } 89 } 90 91 public URL getURL(String name) throws MalformedURLException { 92 URL url = null; 93 if (name.charAt(0) == '/') name = name.substring(1); 94 java.util.jar.JarEntry j = jar.getJarEntry(name); 95 if (j != null) { 96 url = new URL (base, name); 97 } 98 return url; 99 } 100 101 public String getRealPath(String name) { 102 return null; 103 } 104 105 public String getRootPath() { 106 return file.getAbsolutePath(); 107 } 108 109 public void close() throws IOException { 110 jar.close(); 111 } 112 113 public boolean isFile() { return false; } 114 } 115 | Popular Tags |