1 25 26 package org.objectweb.jonas_lib.genbase.archive; 27 28 import java.io.File ; 29 import java.io.FileInputStream ; 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 import java.util.Enumeration ; 33 import java.util.List ; 34 import java.util.Vector ; 35 import java.util.jar.JarFile ; 36 import java.util.zip.ZipEntry ; 37 38 import org.objectweb.jonas_lib.genbase.GenBaseException; 39 40 41 46 public class JarArchive extends AbsArchive { 47 48 49 private JarFile jar; 50 51 58 public JarArchive(File jar) throws GenBaseException { 59 super(jar); 60 61 try { 62 this.jar = new JarFile (jar); 63 setManifest(this.jar.getManifest()); 64 } catch (IOException ioe) { 65 String err = getI18n().getMessage("JarArchive.constr.jar", jar); 66 throw new GenBaseException(err, ioe); 67 } 68 } 69 70 80 public InputStream getInputStream(String filename) throws IOException { 81 File file = (File ) getFiles().get(filename); 83 84 if (file == null) { 85 ZipEntry ze = jar.getEntry(filename); 88 89 if (ze == null) { 91 return null; 92 } else { 93 return jar.getInputStream(ze); 94 } 95 } else { 96 return new FileInputStream (file); 98 } 99 } 100 101 107 public List getContainedFiles() { 108 List list = new Vector (getFiles().keySet()); 109 110 for (Enumeration e = jar.entries(); e.hasMoreElements();) { 112 ZipEntry ze = (ZipEntry ) e.nextElement(); 113 list.add(ze.getName()); 114 } 115 116 return list; 117 } 118 119 124 public boolean isPacked() { 125 return true; 126 } 127 128 131 public void close() { 132 super.close(); 133 try { 134 jar.close(); 135 } catch (IOException ioe) { 136 throw new RuntimeException ("Cannot close file '" + jar + "'", ioe); 137 } 138 jar = null; 139 } 140 } | Popular Tags |