import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import java.io.Writer;




public class XMLSaver {

	private Loader loader;
	String fileStream = "";
	String path = "";
	
	public void saveXML (String pathXML, String fileStreamXML)  {
		try {
			FileOutputStream fos = new FileOutputStream(pathXML);  
			Writer out = new OutputStreamWriter(fos, "UTF8");
			fileStreamXML+="\n</Mpeg7>";
			out.write(fileStreamXML);  
			out.close();
			
			/*PrintWriter out = new PrintWriter(pathXML, fileStreamXML);
			out.println(fileStream);
			out.close();*/
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	XMLSaver(Loader loader){
		this.loader = loader;
		path = loader.getPath();
	}
	
	public String histogram (int colorspace, int q) {
		int bitdiscarded=0;
		String s = null;
		HistogramSet hs = new HistogramSet();
		hs = ScalableColor.getHistogram(loader.getBufferedImage(), colorspace);
		if (q<256) {
			hs = ScalableColor.HaarTransform(hs, q);
		}		
		XMLSyntax syntax = new XMLSyntax();
		s = syntax.ScalableColorXML(hs, q, bitdiscarded);
		System.out.println(s);
		return s;		
	}
	
	public String dominantColor(int method, int dcolors){
		String s= null;
		VectorSet vs = new VectorSet();
		vs = DominantColor.getDominantColor(loader.getBufferedImage(), method, dcolors);
		XMLSyntax syntax = new XMLSyntax();
		s = syntax.DominantColorXML(vs, dcolors, method);
		System.out.println(s);
		return s;
	}	
}


