1 23 24 package org.objectweb.jorm.util.io.lib; 25 26 import java.io.File ; 27 import java.io.FileWriter ; 28 import java.util.Hashtable ; 29 import java.util.Iterator ; 30 import java.util.Properties ; 31 32 import org.objectweb.jorm.util.io.api.TargetHolder; 33 34 37 public class JavaFileHolder implements TargetHolder { 38 39 private Hashtable name2fw = null; 40 41 private File targetDirectory = null; 42 43 public JavaFileHolder(String _targetDirectory) throws Exception { 44 name2fw = new Hashtable (); 45 if (_targetDirectory == null) { 46 String currentDir = System.getProperties().getProperty("user.dir"); 47 targetDirectory = new File (currentDir); 48 } else { 49 targetDirectory = new File (_targetDirectory); 50 } 51 if (!targetDirectory.isDirectory()) 52 throw new Exception ("The parameter must be a directory."); 53 } 54 55 57 61 public synchronized FileWriter getFileWriter(String fileName) throws Exception { 62 File child = new File (targetDirectory, fileName); 63 FileWriter result = (FileWriter ) name2fw.get(child); 64 if (result == null) { 65 67 File parentDir = child.getParentFile(); 68 if (!parentDir.exists()) { 69 parentDir.mkdirs(); 71 } 72 73 child.createNewFile(); 75 result = new FileWriter (child); 76 name2fw.put(child, result); 77 } 78 return result; 79 } 80 81 85 public synchronized Iterator iterateFile() { 86 return name2fw.keySet().iterator(); 87 } 88 89 93 public synchronized Iterator iterateFileWriter() { 94 return name2fw.entrySet().iterator(); 95 } 96 97 100 public synchronized void javacAll() throws Exception { 101 } 103 } 104 | Popular Tags |