private void tidyFileAway(File f, String extension) { File rename = new File(f.getAbsolutePath() + "." + extension); while (rename.exists()) { rename = new File(rename.getAbsolutePath() + "." + extension); } getLog() .warn( "Tidying " + f.getAbsolutePath() + " out of the way, by adding ." + extension, "It will be called: " + rename.getAbsolutePath() + " see log above for detail of problem."); f.renameTo(rename); }
private long persist(File f, ObjectName name) { long deployed = f.lastModified(); try { Element e = (Element) server.getAttribute(name, "Persist"); if (e != null) { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); Document doc = new Document(); e.detach(); doc.setRootElement(e); File tmp = new File(f.getAbsolutePath() + ".tmp"); FileWriter writer = new FileWriter(tmp); out.output(doc, writer); writer.close(); f.delete(); tmp.renameTo(f); deployed = f.lastModified(); } } catch (Exception ex) { log.warn("persist", ex); } return deployed; }