public static void saveToFile(CustomTestStep customStep, IFile file) { String xml = new CubicTestXStream().toXML(customStep); try { String charset = TestPersistance.getCharset(file.getLocation().toFile()); String charsetHeader = TestPersistance.getCharsetHeader(charset); xml = charsetHeader + "\n" + xml; FileUtils.writeStringToFile(file.getLocation().toFile(), xml, charset); } catch (IOException e) { ErrorHandler.logAndRethrow(e); } }
public static CustomTestStep loadFromFile(File file) { String xml = ""; try { String charset = TestPersistance.getCharset(file); xml = FileUtils.readFileToString(file, charset); } catch (FileNotFoundException e) { Logger.error("Error loading test.", e); throw new TestNotFoundException(e.getMessage()); } catch (IOException e) { ErrorHandler.logAndRethrow(e); } CustomTestStep customStep = null; try { customStep = (CustomTestStep) new CubicTestXStream().fromXML(xml); return customStep; } catch (StreamException e) { } if (customStep == null) customStep = new CustomTestStep(); return customStep; }