JarArchive.java

00001 
00026 package org.objectweb.jonas_lib.genbase.archive;
00027 
00028 import java.io.File;
00029 import java.io.FileInputStream;
00030 import java.io.IOException;
00031 import java.io.InputStream;
00032 import java.util.Enumeration;
00033 import java.util.List;
00034 import java.util.Vector;
00035 import java.util.jar.JarFile;
00036 import java.util.zip.ZipEntry;
00037 
00038 import org.objectweb.jonas_lib.genbase.GenBaseException;
00039 
00040 
00046 public class JarArchive extends AbsArchive {
00047 
00049     private JarFile jar;
00050 
00058     public JarArchive(File jar) throws GenBaseException {
00059         super(jar);
00060 
00061         try {
00062             this.jar = new JarFile(jar);
00063             setManifest(this.jar.getManifest());
00064         } catch (IOException ioe) {
00065             String err = getI18n().getMessage("JarArchive.constr.jar", jar);
00066             throw new GenBaseException(err, ioe);
00067         }
00068     }
00069 
00080     public InputStream getInputStream(String filename) throws IOException {
00081         // try get the file from the map
00082         File file = (File) getFiles().get(filename);
00083 
00084         if (file == null) {
00085             // filename not found in added files
00086             // try jar search
00087             ZipEntry ze = jar.getEntry(filename);
00088 
00089             // Entry found ?
00090             if (ze == null) {
00091                 return null;
00092             } else {
00093                 return jar.getInputStream(ze);
00094             }
00095         } else {
00096             // file exists (in added files)
00097             return new FileInputStream(file);
00098         }
00099     }
00100 
00107     public List getContainedFiles() {
00108         List list = new Vector(getFiles().keySet());
00109 
00110         // add files of the original archive
00111         for (Enumeration e = jar.entries(); e.hasMoreElements();) {
00112             ZipEntry ze = (ZipEntry) e.nextElement();
00113             list.add(ze.getName());
00114         }
00115 
00116         return list;
00117     }
00118 
00124     public boolean isPacked() {
00125         return true;
00126     }
00127 }

Generated on Tue Feb 15 15:05:51 2005 for JOnAS by  doxygen 1.3.9.1