try
{
java.util.zip.ZipOutputStream zos = null;
CipherOutputStream cos = null;
// Check whether we need to encrypt the file content:
if (passCode != null && passCode.length() > 0)
{
// Write IV as a prefix:
SecureRandom random = new SecureRandom();
byte[] iv = new byte[IV_LENGTH];
random.nextBytes(iv);
os.write(iv);
os.flush();
Cipher cipher = null;
try
{
cipher = getCipher(Cipher.ENCRYPT_MODE, passCode, iv);
}
catch (GeneralSecurityException gse)
{
throw new ManifoldCFException("Could not encrypt configuratiom file: " + gse.getMessage());
}
cos = new CipherOutputStream(os, cipher);
zos = new java.util.zip.ZipOutputStream(cos);
}
else
zos = new java.util.zip.ZipOutputStream(os);
try
{
// Now, work within a transaction.
database.beginTransaction();
try
{
// At the outermost level, I've decided that the best structure is to have a zipentry for each
// manager. Each manager must manage its own data as a binary blob, including any format versioning information,
// This guarantees flexibility for the future.
// The zipentries must be written in an order that permits their proper restoration. The "lowest level" is thus
// written first, which yields the order: authority connections, repository connections, jobs
java.util.zip.ZipEntry outputEntry = new java.util.zip.ZipEntry("outputs");
zos.putNextEntry(outputEntry);
outputManager.exportConfiguration(zos);
zos.closeEntry();
java.util.zip.ZipEntry mappingEntry = new java.util.zip.ZipEntry("mappings");
zos.putNextEntry(mappingEntry);
mappingManager.exportConfiguration(zos);
zos.closeEntry();
java.util.zip.ZipEntry authEntry = new java.util.zip.ZipEntry("authorities");
zos.putNextEntry(authEntry);
authManager.exportConfiguration(zos);
zos.closeEntry();
java.util.zip.ZipEntry connEntry = new java.util.zip.ZipEntry("connections");
zos.putNextEntry(connEntry);
connManager.exportConfiguration(zos);
zos.closeEntry();
java.util.zip.ZipEntry jobsEntry = new java.util.zip.ZipEntry("jobs");
zos.putNextEntry(jobsEntry);
jobManager.exportConfiguration(zos);
zos.closeEntry();
// All done
}
catch (ManifoldCFException e)
{
database.signalRollback();
throw e;
}
catch (Error e)
{
database.signalRollback();
throw e;
}
finally
{
database.endTransaction();
}
}
finally
{
zos.close();
if (cos != null) {
cos.close();
}
}
}
finally
{