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 31 import org.objectweb.jonas_lib.genbase.GenBaseException; 32 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 33 34 39 public class DirStorer extends ArchiveStorer { 40 41 44 private File base; 45 46 54 public DirStorer(J2EEArchive archive, File dir) throws GenBaseException { 55 super(archive); 56 57 setOut(dir.getAbsolutePath()); 58 59 if (!dir.exists()) { 61 if (!dir.mkdirs()) { 62 String err = getI18n().getMessage("DirStorer.constr.create", dir); 63 throw new GenBaseException(err); 64 } 65 } 66 67 base = dir; 68 } 69 70 77 protected String convertName(String name) { 78 return name.replace('/', File.separatorChar); 79 } 80 81 88 protected void addFile(String name) throws IOException { 89 OutputStream fos = getOutputStream(name); 90 InputStream is = getArchive().getInputStream(name); 91 fill(is, fos); 92 is.close(); 93 } 94 95 104 protected OutputStream getOutputStream(String name) throws IOException { 105 File out = new File (base, convertName(name)); 106 File parent = out.getParentFile(); 107 108 if (!parent.exists()) { 109 if (!parent.mkdirs()) { 110 String err = getI18n().getMessage("DirStorer.getOutputStream.create", out); 111 throw new IOException (err); 112 } 113 } 114 115 OutputStream os = new FileOutputStream (out); 116 117 return os; 118 } 119 } | Popular Tags |