use of com.revolsys.record.io.format.saif.util.OsnSerializer in project com.revolsys.open by revolsys.
the class SaifWriter method close.
@Override
public synchronized void close() {
if (this.tempDirectory != null) {
try {
if (log.isInfoEnabled()) {
log.info("Closing SAIF archive '" + this.file.getCanonicalPath() + "'");
}
writeExports();
writeMissingDirObject("InternallyReferencedObjects", "internal.dir");
writeMissingDirObject("ImportedObjects", "imports.dir");
writeMissingGlobalMetadata();
if (log.isInfoEnabled()) {
log.info(" Closing serializers");
}
for (final OsnSerializer serializer : this.serializers.values()) {
try {
serializer.close();
} catch (final Throwable e) {
log.error(e.getMessage(), e);
}
}
if (log.isDebugEnabled()) {
log.debug(" Compressing SAIF archive");
}
if (!this.file.isDirectory()) {
ZipUtil.zipDirectory(this.file, this.tempDirectory);
}
} catch (final RuntimeException e) {
this.file.delete();
throw e;
} catch (final Error e) {
this.file.delete();
throw e;
} catch (final IOException e) {
log.error(" Unable to compress SAIF archive: " + e.getMessage(), e);
e.printStackTrace();
} finally {
if (log.isDebugEnabled()) {
log.debug(" Deleting temporary files");
}
if (!this.file.isDirectory()) {
FileUtil.deleteDirectory(this.tempDirectory);
if (log.isDebugEnabled()) {
log.debug(" Finished closing file");
}
}
this.tempDirectory = null;
}
}
}
Aggregations