use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class TamperDeterrent method addThumbprint.
/**
* Read a file and write a new version containing a tamper-detection
* thumbprint.
*
* @param src
* the file to read. The file might or might not contain a
* thumbprint already. If it does, the existing thumbprint will
* be removed.
* @param dest
* the file where the 'signed' data should be written. Can be the
* same as <tt>src</tt>
* @param t
* the type of data the file contains
* @throws IOException
* if data could not be read or written
* @throws AccessControlException
* if this method is called by untrusted code. (Only core
* dashboard logic should be calling this method.)
*/
public final void addThumbprint(File src, File dest, FileType t) throws IOException, AccessControlException {
// only allow trusted code to add thumbprints to files
PERMISSION.checkPermission();
// if this is the no-op implementation, abort without changing the file
String thisType = getThumbprintType();
if (thisType == null) {
if (!src.equals(dest)) {
RobustFileOutputStream out = new RobustFileOutputStream(dest);
FileUtils.copyFile(src, out);
out.close();
}
return;
}
// read the file and calculate the thumbprint
FileData fileData = readFile(src, t);
fileData.thumbprint = null;
calcThumbprint(fileData);
String thumbData = thisType + SEP + fileData.thumbprint;
// write the file as requested, with the new thumbprint at the end
OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(dest));
if (fileData.thumbStartPos > 0)
out.write(fileData.content, 0, fileData.thumbStartPos);
if (fileData.thumbEndPos < fileData.content.length)
out.write(fileData.content, fileData.thumbEndPos, fileData.content.length - fileData.thumbEndPos);
out.write(t.thumbStart);
out.write(thumbData.getBytes(t.encoding));
out.write(t.thumbEnd);
out.close();
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class UserGroupManager method saveFile.
private void saveFile(boolean custom) throws IOException {
// find the file that should be modified
File targetFile = custom ? customFile : sharedFile;
targetFile.getParentFile().mkdirs();
OutputStream out = new BufferedOutputStream(new RobustFileOutputStream(targetFile));
// start an XML document
XmlSerializer xml = XMLUtils.getXmlSerializer(true);
xml.setOutput(out, "UTF-8");
xml.startDocument("UTF-8", null);
xml.startTag(null, GROUPS_TAG);
// write the data timestamp, if we have one
Date ts = timestamps.get(custom);
if (ts != null)
xml.attribute(null, TIMESTAMP_ATTR, XMLUtils.saveDate(ts));
// write XML for each group
List<UserGroup> groups = new ArrayList<UserGroup>(this.groups.values());
Collections.sort(groups);
for (UserGroup oneGroup : groups) {
if (oneGroup.isCustom() == custom)
oneGroup.getAsXml(xml);
}
// end the document and close the file
xml.endTag(null, GROUPS_TAG);
xml.ignorableWhitespace(System.lineSeparator());
xml.endDocument();
out.close();
// add a tamper-deterrent thumbprint to the shared groups file.
if (!custom) {
TamperDeterrent.getInstance().addThumbprint(targetFile, targetFile, TamperDeterrent.FileType.XML);
}
// if we saved the file successfully, clear its dirty flag
needsSave.remove(custom);
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class DatasetAutoMigrator method copyDataFiles.
private void copyDataFiles() throws IOException {
// Copy all important data files from the source directory to the
// working directory.
File destDir = workingDir.getDirectory();
List<String> files = FileUtils.listRecursively(sourceDir, DashboardInstanceStrategy.INSTANCE.getFilenameFilter());
for (String filename : files) {
File srcFile = new File(sourceDir, filename);
File destFile = new File(destDir, filename);
RobustFileOutputStream out = new RobustFileOutputStream(destFile);
FileUtils.copyFile(srcFile, out);
out.close();
}
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class CompressedWorkingDirectory method flushData.
public boolean flushData() throws LockFailureException, IOException {
List<String> filesToBackup = FileUtils.listRecursively(extractDirectory, CWD_FILE_FILTER);
File destZip = getTargetZipFile();
RobustFileOutputStream rOut = new RobustFileOutputStream(destZip);
OutputStream out = rOut;
if (isPdbk(destZip))
out = new XorOutputStream(out, PDBK_XOR_BITS);
try {
ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(out));
for (String filename : filesToBackup) {
File f = new File(extractDirectory, filename);
ZipEntry e = new ZipEntry(filename);
e.setTime(f.lastModified());
zipOut.putNextEntry(e);
FileUtils.copyFile(f, zipOut);
zipOut.closeEntry();
}
zipOut.finish();
zipOut.flush();
} catch (IOException ioe) {
rOut.abort();
throw ioe;
}
out.close();
return true;
}
use of net.sourceforge.processdash.util.RobustFileOutputStream in project processdash by dtuma.
the class TeamProject method saveUserSettings.
private boolean saveUserSettings(File directory) {
File userSettingsFile = new File(directory, USER_SETTINGS_FILENAME);
try {
RobustFileOutputStream out = new RobustFileOutputStream(userSettingsFile);
userSettings.store(out, null);
out.close();
return true;
} catch (IOException ioe) {
System.out.println("Encountered problem when saving " + userSettingsFile);
ioe.printStackTrace();
return false;
}
}
Aggregations