use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.
the class WorkingTimeLog method doCleanup.
private synchronized void doCleanup(Iterator timeLogEntries) throws IOException {
if (Settings.isReadOnly())
return;
// start by writing the output to a temporary file. Although we could
// actually write directly to the destination file, that would be
// relying on implementation details (of both TimeLogReader and
// RobustFileWriter) that we should know nothing about.
File tempFile = TempFileFactory.get().createTempFile("timelog", ".xml");
RobustFileWriter rout = new RobustFileWriter(tempFile, TIME_LOG_ENCODING);
BufferedWriter out = new BufferedWriter(rout);
TimeLogWriter.write(out, timeLogEntries);
out.close();
long checksum1 = rout.getChecksum();
// Now, copy the file we just created to its real destination.
File destFile = getFile(TIME_LOG_FILENAME);
Reader in = new BufferedReader(new InputStreamReader(new FileInputStream(tempFile), TIME_LOG_ENCODING));
rout = new RobustFileWriter(destFile, TIME_LOG_ENCODING);
out = new BufferedWriter(rout);
int c;
while (true) {
c = in.read();
if (c == -1)
break;
out.write(c);
}
out.flush();
// we're done with the temporary file. Close and delete it.
try {
in.close();
tempFile.delete();
} catch (IOException ioe) {
ioe.printStackTrace();
}
long checksum2 = rout.getChecksum();
if (checksum1 != checksum2) {
// if the contents we just copied didn't match the first version of
// the file we wrote, abort. This would only happen in the rare
// circumstance when we wrote and verified one thing to the temp
// file, then read it back differently.
rout.abort();
throw new IOException("Unable to save time log to file " + destFile);
} else {
rout.close();
realTimeMods.clear();
}
}
use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.
the class MigrationToolTeam method convertDatafileContents.
private void convertDatafileContents(File dataFile) throws IOException {
StringBuffer contents = slurpFile(dataFile);
String oldIncludeStr = "#include <" + currentPID + "/";
String newIncludeStr = "#include <" + targetPID + "/";
StringUtils.findAndReplace(contents, oldIncludeStr, newIncludeStr);
Writer out = new BufferedWriter(new RobustFileWriter(dataFile));
out.write(contents.toString());
out.close();
}
use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.
the class MigrationToolTeam method updateSettingsXmlFile.
private void updateSettingsXmlFile() throws IOException {
String jarName = tryToCopyProcessJar();
File settingsFile = new File(teamDataDirectory, "settings.xml");
StringBuffer settings = slurpFile(settingsFile);
String oldPIDLine = "processID='" + currentPID + "'";
String newPIDLine = "processID='" + targetPID + "'";
StringUtils.findAndReplace(settings, oldPIDLine, newPIDLine);
if (jarName != null) {
Pattern p = Pattern.compile("/Templates/(.*\\.zip)");
Matcher m = p.matcher(settings);
if (m.find())
settings.replace(m.start(1), m.end(1), XMLUtils.escapeAttribute(jarName));
}
Writer out = new BufferedWriter(new RobustFileWriter(settingsFile));
out.write(settings.toString());
out.close();
}
use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.
the class DashHierarchy method saveXML.
public void saveXML(String filename, String comment) throws IOException {
if (Settings.isReadOnly())
return;
BufferedWriter out = new BufferedWriter(new RobustFileWriter(filename, "UTF-8"));
out.write(XML_HEADER);
out.newLine();
out.newLine();
if (comment != null && comment.length() != 0) {
out.write("<!-- " + XMLUtils.escapeAttribute(comment) + " -->");
out.newLine();
out.newLine();
}
saveXMLNode(out, 0, PropertyKey.ROOT, false);
out.close();
}
use of net.sourceforge.processdash.util.RobustFileWriter in project processdash by dtuma.
the class TeamProject method saveColumns.
/** Save the project milestones */
private boolean saveColumns(File directory) {
try {
File f = new File(directory, COLUMNS_FILENAME);
RobustFileWriter out = new RobustFileWriter(f, "UTF-8");
BufferedWriter buf = new BufferedWriter(out);
columnSpecs.getAsXML(buf);
buf.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
Aggregations