package org.adligo.xml_io.generator;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.adligo.models.params.client.I_TemplateParams;
import org.adligo.xml.parsers.template.Template;
import org.adligo.xml.parsers.template.TemplateParserEngine;

public class SourceFileWriter {
	private Template template;
	private String dir;
	
	public void writeSourceFile(String clazzName, I_TemplateParams params) throws IOException {
		try {
			String filePath = dir + File.separator + clazzName + ".java";
			File file = new File(filePath);
			file.createNewFile();
			FileOutputStream fos = new FileOutputStream(file);
			String result = TemplateParserEngine.parse(template, params);
			fos.write(result.getBytes("UTF-16"));
			fos.close();
		} catch (UnsupportedEncodingException x) {
			throw new IllegalStateException("the encoding UTF-16 is required by the java specification");
		} catch (FileNotFoundException p) {
			throw new IOException(p);
		}
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}
}

@@ -123,16 +123,43 @@
 Stream;%0A
+import java.io.FileWriter;%0A
 import j
@@ -820,16 +820,20 @@
 arams);%0A
+%09%09%09%0A
 %09%09%09fos.w
@@ -854,22 +854,21 @@
 tBytes(%22
-UTF-16
+ASCII
 %22));%0A%09%09%09
@@ -978,14 +978,13 @@
 ing 
-UTF-16
+ASCII
  is 

ahh it was ASCII not UTF-16