1 package org.javagen.agile.core.emitter;
2
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FileWriter;
6 import java.io.IOException;
7 import java.io.Writer;
8 import org.javagen.agile.core.util.FileUtil;
9
10 /***
11 * This default <code>WriterFactory</code> just creates a <code>FileWriter</code> instance
12 * after making sure the parent directory exists.
13 *
14 * @author Richard Easterling
15 */
16 public class DefaultWriterFactory implements WriterFactory {
17
18 /***
19 * Create an output sink given a output file.
20 */
21 public Writer createWriter(File outputFile) {
22 try {
23 FileUtil.createDir(outputFile);
24 BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
25 return writer;
26 } catch (IOException e) {
27 throw new RuntimeException(e);
28 }
29 }
30
31 }