* @param input abstract archive to copy old elements from
* @param outPath the file to use
*/
public void write(AbstractArchive in, String outPath) throws IOException {
AbstractArchive oldArchive=null;
try {
oldArchive = abstractArchiveFactory.openArchive(outPath);
} catch (IOException ioe) {
// there could be many reasons why we cannot open this archive,
// we should continue
}
AbstractArchive out = null;
BufferedOutputStream bos=null;
try {
String tmpName = null;
if (oldArchive!=null && oldArchive.exists() &&
!oldArchive.supportsElementsOverwriting()) {
// this is a rewrite, get a temp file name...
// I am creating a tmp file just to get a name
File outputFile = getTempFile(outPath);
tmpName = outputFile.getAbsolutePath();
outputFile.delete();
out = abstractArchiveFactory.createArchive(tmpName);
oldArchive.close();
} else {
out = abstractArchiveFactory.createArchive(outPath);
}
// write archivist content
writeContents(in, out);
out.close();
in.close();
// if we were using a temp file, time to rewrite the original
if (tmpName!=null) {
AbstractArchive finalArchive = abstractArchiveFactory.openArchive(outPath);
finalArchive.delete();
AbstractArchive tmpArchive = abstractArchiveFactory.openArchive(tmpName);
tmpArchive.renameTo(outPath);
}
} catch (IOException ioe) {
// cleanup
if (out!=null) {
try {