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
00031 import org.objectweb.jonas_lib.genbase.GenBaseException;
00032 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
00033
00039 public class DirStorer extends ArchiveStorer {
00040
00044 private File base;
00045
00054 public DirStorer(J2EEArchive archive, File dir) throws GenBaseException {
00055 super(archive);
00056
00057 setOut(dir.getAbsolutePath());
00058
00059
00060 if (!dir.exists()) {
00061 if (!dir.mkdirs()) {
00062 String err = getI18n().getMessage("DirStorer.constr.create", dir);
00063 throw new GenBaseException(err);
00064 }
00065 }
00066
00067 base = dir;
00068 }
00069
00077 protected String convertName(String name) {
00078 return name.replace('/', File.separatorChar);
00079 }
00080
00088 protected void addFile(String name) throws IOException {
00089 OutputStream fos = getOutputStream(name);
00090 InputStream is = getArchive().getInputStream(name);
00091 fill(is, fos);
00092 is.close();
00093 }
00094
00104 protected OutputStream getOutputStream(String name) throws IOException {
00105 File out = new File(base, convertName(name));
00106 File parent = out.getParentFile();
00107
00108 if (!parent.exists()) {
00109 if (!parent.mkdirs()) {
00110 String err = getI18n().getMessage("DirStorer.getOutputStream.create", out);
00111 throw new IOException(err);
00112 }
00113 }
00114
00115 OutputStream os = new FileOutputStream(out);
00116
00117 return os;
00118 }
00119 }