1 11 12 package org.eclipse.osgi.framework.adaptor.core; 13 14 import java.io.*; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.zip.ZipEntry ; 18 19 26 public abstract class BundleEntry { 27 33 public abstract InputStream getInputStream() throws IOException; 34 35 40 public abstract long getSize(); 41 42 47 public abstract String getName(); 48 49 56 public abstract long getTime(); 57 58 63 public abstract URL getLocalURL(); 64 65 71 public abstract URL getFileURL(); 72 73 78 public String toString() { 79 return (getName()); 80 } 81 82 86 public static class ZipBundleEntry extends BundleEntry { 87 90 protected ZipEntry zipEntry; 91 92 95 protected BundleFile bundleFile; 96 97 102 protected ZipBundleEntry(ZipEntry entry, BundleFile bundleFile) { 103 this.zipEntry = entry; 104 this.bundleFile = bundleFile; 105 } 106 107 113 public InputStream getInputStream() throws IOException { 114 return ((BundleFile.ZipBundleFile) bundleFile).getZipFile().getInputStream(zipEntry); 115 } 116 117 122 public long getSize() { 123 return zipEntry.getSize(); 124 } 125 126 131 public String getName() { 132 return zipEntry.getName(); 133 } 134 135 142 public long getTime() { 143 return zipEntry.getTime(); 144 } 145 146 public URL getLocalURL() { 147 try { 148 return new URL ("jar:file:" + bundleFile.basefile.getAbsolutePath() + "!/" + zipEntry.getName()); } catch (MalformedURLException e) { 150 return null; 152 } 153 } 154 155 public URL getFileURL() { 156 try { 157 File file = bundleFile.getFile(zipEntry.getName()); 158 if (file != null) 159 return file.toURL(); 160 } catch (MalformedURLException e) { 161 } 163 return null; 164 } 165 } 166 167 171 public static class FileBundleEntry extends BundleEntry { 172 175 private File file; 176 179 private String name; 180 181 186 FileBundleEntry(File file, String name) { 187 this.file = file; 188 this.name = name; 189 } 190 191 197 public InputStream getInputStream() throws IOException { 198 return BundleFile.secureAction.getFileInputStream(file); 199 } 200 201 206 public long getSize() { 207 return BundleFile.secureAction.length(file); 208 } 209 210 215 public String getName() { 216 return (name); 217 } 218 219 226 public long getTime() { 227 return BundleFile.secureAction.lastModified(file); 228 } 229 230 public URL getLocalURL() { 231 return getFileURL(); 232 } 233 234 public URL getFileURL() { 235 try { 236 return file.toURL(); 237 } catch (MalformedURLException e) { 238 return null; 239 } 240 } 241 } 242 243 248 public static class DirZipBundleEntry extends BundleEntry { 249 250 253 private BundleFile.ZipBundleFile bundleFile; 254 257 private String name; 258 259 public DirZipBundleEntry(BundleFile.ZipBundleFile bundleFile, String name) { 260 this.name = (name.length() > 0 && name.charAt(0) == '/') ? name.substring(1) : name; 261 this.bundleFile = bundleFile; 262 } 263 264 public InputStream getInputStream() throws IOException { 265 return null; 266 } 267 268 public long getSize() { 269 return 0; 270 } 271 272 public String getName() { 273 return name; 274 } 275 276 public long getTime() { 277 return 0; 278 } 279 280 public URL getLocalURL() { 281 try { 282 return new URL ("jar:file:" + bundleFile.basefile.getAbsolutePath() + "!/" + name); } catch (MalformedURLException e) { 284 return null; 286 } 287 } 288 289 public URL getFileURL() { 290 try { 291 return bundleFile.extractDirectory(name).toURL(); 292 } catch (MalformedURLException e) { 293 return null; 295 } 296 } 297 } 298 } 299 | Popular Tags |