Search in sources :

Example 6 with OsnSerializer

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;
        }
    }
}
Also used : OsnSerializer(com.revolsys.record.io.format.saif.util.OsnSerializer) IOException(java.io.IOException)

Aggregations

OsnSerializer (com.revolsys.record.io.format.saif.util.OsnSerializer)6 IOException (java.io.IOException)4 File (java.io.File)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1