use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class ExportFileStream method copyToDestFile.
private void copyToDestFile(long checksum) throws IOException {
RobustFileOutputStream out = new RobustFileOutputStream(directFile, false);
FileUtils.copyFile(tempOutFile, out);
long copySum = out.getChecksum();
if (copySum == checksum) {
out.close();
target = directFile;
} else {
out.abort();
throw new IOException("Error writing to " + directFile + " - checksums do not match");
}
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class TemplateSynchronizer method writeTemplateXml.
private void writeTemplateXml(List workflows, Map templates) throws IOException {
XmlSerializer ser = XMLUtils.getXmlSerializer(true);
genericOldSubtaskTemplate = (Element) templates.get(processID + "/IndivEmptyNode");
genericNewSubtaskTemplate = (Element) templates.get(processID + "/Indiv2Task");
phaseIDs = HierarchySynchronizer.initPhaseIDs(processID);
effectivePhaseDataName = HierarchySynchronizer.getEffectivePhaseDataName(processID);
projectNamePrefix = getProjectNamePrefix(projectPath);
OutputStream out = new RobustFileOutputStream(destFile);
ser.setOutput(out, ENCODING);
ser.startDocument(ENCODING, null);
ser.startTag(null, DOC_ROOT_ELEM);
for (Iterator i = workflows.iterator(); i.hasNext(); ) {
Element workflow = (Element) i.next();
writeTemplate(ser, workflow);
}
ser.endTag(null, DOC_ROOT_ELEM);
ser.flush();
out.close();
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class PermissionsManager method saveUsers.
/**
* Save in-memory user information to disk.
*/
private void saveUsers() {
try {
if (Settings.isReadOnly() || Settings.isPersonalMode())
return;
// open a file to save the users
File tmp = TempFileFactory.get().createTempFile("users", ".dat");
OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(tmp));
// start an XML document
XmlSerializer xml = XMLUtils.getXmlSerializer(true);
xml.setOutput(out, "UTF-8");
xml.startDocument("UTF-8", null);
xml.startTag(null, USERS_TAG);
if (usersTimestamp != null)
xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(usersTimestamp));
// write XML for each user
for (User u : getAllUsers()) {
writeUser(xml, u);
}
// end the document and close the file
xml.endTag(null, USERS_TAG);
xml.ignorableWhitespace(System.lineSeparator());
xml.endDocument();
out.close();
// add a tamper-deterrent thumbprint to the file
TamperDeterrent.getInstance().addThumbprint(tmp, usersFile, TamperDeterrent.FileType.XML);
tmp.delete();
// from now forward, require a version of the dashboard that
// understands and enforces users, roles and permissions
DataVersionChecker.registerDataRequirement("pspdash", "2.3.2");
// flush data so the PDES can update server-side permissions
if (bridgedUrl != null)
workingDir.flushData();
this.usersDirty = false;
} catch (IOException ioe) {
logger.log(Level.WARNING, "Could not save users to " + usersFile, ioe);
} catch (LockFailureException lfe) {
logger.log(Level.WARNING, "Could not flush user data to server", lfe);
}
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class DefectLog method saveAsXML.
private void saveAsXML(Defect[] defects) {
try {
RobustFileOutputStream out = new RobustFileOutputStream(defectLogFilename);
if (defects != null && defects.length > 0) {
XmlSerializer ser = XMLUtils.getXmlSerializer(true);
ser.setOutput(out, XmlConstants.ENCODING);
ser.startDocument(XmlConstants.ENCODING, null);
ser.startTag(null, "defectLog");
for (int i = 0; i < defects.length; i++) if (defects[i] != null)
defects[i].toXml(ser);
ser.endTag(null, "defectLog");
ser.endDocument();
}
out.close();
} catch (IOException e) {
System.out.println("IOException: " + e);
}
;
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class PermissionsManager method saveRoles.
/**
* Save in-memory role information to disk.
*/
private void saveRoles() {
try {
if (Settings.isReadOnly() || Settings.isPersonalMode())
return;
// open a file to save the roles
File tmp = TempFileFactory.get().createTempFile("roles", ".dat");
OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(tmp));
// start an XML document
XmlSerializer xml = XMLUtils.getXmlSerializer(true);
xml.setOutput(out, "UTF-8");
xml.startDocument("UTF-8", null);
xml.startTag(null, ROLES_TAG);
if (rolesTimestamp != null)
xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(rolesTimestamp));
// write XML for each role
for (Role r : getAllRoles()) {
writeRole(xml, r);
}
// end the document and close the file
xml.endTag(null, ROLES_TAG);
xml.ignorableWhitespace(System.lineSeparator());
xml.endDocument();
out.close();
// add a tamper-deterrent thumbprint to the file
TamperDeterrent.getInstance().addThumbprint(tmp, rolesFile, TamperDeterrent.FileType.XML);
tmp.delete();
// from now forward, require a version of the dashboard that
// understands and enforces users, roles and permissions
DataVersionChecker.registerDataRequirement("pspdash", "2.3.2");
this.rolesDirty = false;
} catch (IOException ioe) {
logger.log(Level.WARNING, "Could not save roles to " + rolesFile, ioe);
}
}
Aggregations