1 22 23 package org.objectweb.jonas_lib.genbase.utils; 24 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.io.OutputStream ; 30 import java.util.jar.JarOutputStream ; 31 import java.util.zip.ZipEntry ; 32 33 import org.objectweb.jonas_lib.genbase.GenBaseException; 34 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 35 36 41 public class JarStorer extends ArchiveStorer { 42 43 46 private JarOutputStream jos; 47 48 56 public JarStorer(J2EEArchive archive, File jar) throws GenBaseException { 57 super(archive); 58 59 setOut(jar.getAbsolutePath()); 60 61 try { 62 if (!jar.getParentFile().exists()) { 63 if (!jar.getParentFile().mkdirs()) { 64 String err = getI18n().getMessage("JarStorer.constr.create", jar.getParentFile()); 65 throw new GenBaseException(err); 66 } 67 } 68 69 jos = new JarOutputStream (new FileOutputStream (jar), archive.getManifest()); 70 } catch (IOException ioe) { 71 String err = getI18n().getMessage("JarStorer.constr.ioe", jar); 72 throw new GenBaseException(err, ioe); 73 } 74 } 75 76 83 protected String convertName(String name) { 84 return name.replace('\\', '/'); 85 } 86 87 94 protected void addFile(String name) throws IOException { 95 ZipEntry ze = new ZipEntry (convertName(name)); 96 jos.putNextEntry(ze); 97 98 InputStream is = getArchive().getInputStream(name); 99 fill(is, jos); 100 is.close(); 101 } 102 103 108 public void store() throws GenBaseException { 109 super.store(); 110 111 try { 112 jos.close(); 113 } catch (IOException ioe) { 114 String err = getI18n().getMessage("JarStorer.store.close"); 115 throw new GenBaseException(err, ioe); 116 } 117 } 118 119 128 protected OutputStream getOutputStream(String name) throws IOException { 129 ZipEntry ze = new ZipEntry (convertName(name)); 130 jos.putNextEntry(ze); 131 132 return jos; 133 } 134 } | Popular Tags |