1 29 30 package com.caucho.vfs; 31 32 import com.caucho.util.LruCache; 33 34 import java.io.IOException ; 35 import java.security.cert.Certificate ; 36 import java.util.Map ; 37 import java.util.jar.Manifest ; 38 39 42 public class JarPath extends FilesystemPath { 43 private static LruCache<Path,JarPath> _jarCache 44 = new LruCache<Path,JarPath>(256); 45 46 private Path _backing; 47 48 56 protected JarPath(FilesystemPath root, String userPath, 57 String path, Path backing) 58 { 59 super(root, userPath, path); 60 61 if (_root == null) 62 _root = this; 63 64 _backing = backing; 65 } 66 67 70 public static JarPath create(Path backing) 71 { 72 JarPath path = _jarCache.get(backing); 73 74 if (path == null) { 75 path = new JarPath(null, "/", "/", backing); 76 _jarCache.put(backing, path); 77 } 78 79 return path; 80 } 81 82 public Path fsWalk(String userPath, 83 Map <String ,Object > attributes, 84 String path) 85 { 86 if ("/".equals(userPath) && "/".equals(path)) 87 return _root; 88 else 89 return new JarPath(_root, userPath, path, _backing); 90 } 91 92 95 public String getScheme() 96 { 97 return "jar"; 98 } 99 100 105 public String getURL() 106 { 107 String path = getFullPath(); 108 109 return getScheme() + ":" + getContainer().getURL() + "!" + path; 110 } 111 112 115 public Path getContainer() 116 { 117 return getJar().getBacking(); 118 } 119 120 123 @Override 124 public Certificate []getCertificates() 125 { 126 return getJar().getCertificates(getPath()); 127 } 128 129 132 public boolean exists() 133 { 134 return getJar().exists(getPath()); 135 } 136 137 140 public boolean isDirectory() 141 { 142 return getJar().isDirectory(getPath()); 143 } 144 145 148 public boolean isFile() 149 { 150 return getJar().isFile(getPath()); 151 } 152 153 public long getLength() 154 { 155 return getJar().getLength(this); 156 } 157 158 public long getLastModified() 159 { 160 return getJar().getLastModified(getPath()); 161 } 162 163 public boolean canRead() 164 { 165 return getJar().canRead(getPath()); 166 } 167 168 public boolean canWrite() 169 { 170 return getJar().canWrite(getPath()); 171 } 172 173 176 public String []list() throws IOException 177 { 178 return getJar().list(getPath()); 179 } 180 181 184 public Manifest getManifest() throws IOException 185 { 186 return getJar().getManifest(); 187 } 188 189 192 public PersistentDependency getDepend() 193 { 194 return getJar().getDepend(); 195 } 196 197 public StreamImpl openReadImpl() throws IOException 198 { 199 return getJar().openReadImpl(this); 200 } 201 202 protected Jar getJar() 203 { 204 return Jar.create(_backing); 205 } 206 207 public void closeJar() 208 { 209 Jar jar = Jar.getJar(_backing); 210 211 if (jar != null) 212 jar.close(); 213 } 214 215 public String toString() 216 { 217 return "jar:(" + _backing + ")" + getPath(); 218 } 219 220 public int hashCode() 221 { 222 return 65531 * getFullPath().hashCode() + getContainer().hashCode(); 223 } 224 225 228 public boolean equals(Object o) 229 { 230 if (this == o) 231 return true; 232 else if (o == null || ! o.getClass().equals(this.getClass())) 233 return false; 234 235 JarPath jarPath = (JarPath) o; 236 237 return (_backing.equals(jarPath._backing) && 238 getFullPath().equals(jarPath.getFullPath())); 239 } 240 } 241 | Popular Tags |