/** * Author: Christoph Hillebold <c.hillebold@student.tugraz.at> */ package at.iaik.suraq.util; import java.io.File; import java.io.FileWriter; import at.iaik.suraq.smtlib.formula.Formula; /** * This Class is used to generate Debug-Files that contains either Strings or * Formulas. You can set the Folder, where they should be stored by calling * .setFolder(...). * * @author chillebold * */ public class DebugHelper { /** * The only instance of this class. */ private static DebugHelper _instance = null; /** * Private Constructor */ private DebugHelper() { // } /** * Gets a static instance of this class. * * @return */ public static DebugHelper getInstance() { if (DebugHelper._instance == null) DebugHelper._instance = new DebugHelper(); return DebugHelper._instance; } /** * The Default-Folder where the Debug-files (generated by this class) should * go to */ private String folder = "./"; /** * Sets the Folder for the formulatoFile() and stringToFile() methods. If * the folder does not exist, it is created (also parent Folders are * created). * * @param folder */ public void setFolder(String folder) { try { File path = new File(folder); if (!path.exists()) { System.out.println("Folder " + folder + "created."); path.mkdirs(); } if (!path.isDirectory()) throw new RuntimeException("given folder is no path"); this.folder = folder; } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } } /** * Writes the given Formula to the File in filename. This is done by calling * the .toString() method of the Formula. You can change the Folder by * calling .setFolder() of this class. * * @param formula * The Formula to write into the File * @param filename * Filename, where the Formula should go */ public void formulaToFile(Formula formula, String filename) { stringtoFile(formula.toString(), filename); } /** * Writes the given String text to the File in filename. You can change the * Folder by calling .setFolder() of this class. * * @param text * the Text to write into the File * @param filename * Filename, where the Text s You can change the Folder by * calling .setFolder() of this class.hould go */ public void stringtoFile(String text, String filename) { System.out.println("* File written to '" + folder + filename + "'"); try { File debugFile1 = new File(folder + filename); FileWriter fstream = new FileWriter(debugFile1); fstream.write(text); fstream.close(); } catch (Exception ex) { ex.printStackTrace(); } } }