00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package org.objectweb.jonas_lib.genbase.utils;
00024
00025 import java.io.File;
00026 import java.io.FileOutputStream;
00027 import java.io.IOException;
00028 import java.io.InputStream;
00029 import java.io.OutputStream;
00030 import java.util.jar.JarOutputStream;
00031 import java.util.zip.ZipEntry;
00032
00033 import org.objectweb.jonas_lib.genbase.GenBaseException;
00034 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
00035
00041 public class JarStorer extends ArchiveStorer {
00042
00046 private JarOutputStream jos;
00047
00056 public JarStorer(J2EEArchive archive, File jar) throws GenBaseException {
00057 super(archive);
00058
00059 setOut(jar.getAbsolutePath());
00060
00061 try {
00062 if (!jar.getParentFile().exists()) {
00063 if (!jar.getParentFile().mkdirs()) {
00064 String err = getI18n().getMessage("JarStorer.constr.create", jar.getParentFile());
00065 throw new GenBaseException(err);
00066 }
00067 }
00068
00069 jos = new JarOutputStream(new FileOutputStream(jar), archive.getManifest());
00070 } catch (IOException ioe) {
00071 String err = getI18n().getMessage("JarStorer.constr.ioe", jar);
00072 throw new GenBaseException(err, ioe);
00073 }
00074 }
00075
00083 protected String convertName(String name) {
00084 return name.replace('\\', '/');
00085 }
00086
00094 protected void addFile(String name) throws IOException {
00095 ZipEntry ze = new ZipEntry(convertName(name));
00096 jos.putNextEntry(ze);
00097
00098 InputStream is = getArchive().getInputStream(name);
00099 fill(is, jos);
00100 is.close();
00101 }
00102
00108 public void store() throws GenBaseException {
00109 super.store();
00110
00111 try {
00112 jos.close();
00113 } catch (IOException ioe) {
00114 String err = getI18n().getMessage("JarStorer.store.close");
00115 throw new GenBaseException(err, ioe);
00116 }
00117 }
00118
00128 protected OutputStream getOutputStream(String name) throws IOException {
00129 ZipEntry ze = new ZipEntry(convertName(name));
00130 jos.putNextEntry(ze);
00131
00132 return jos;
00133 }
00134 }