public void close ( ) throws JournalException { synchronized ( JournalWriter . SYNCHRONIZER ) { if ( ! open ) { return ; } try { parent . getDocumentTrailer ( xmlWriter ) ; xmlWriter . close ( ) ; fileWriter . close ( ) ; timer . cancel ( ) ; /* * java.io.File.renameTo() has a known bug when working across * file-systems, see: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4073756 So * instead of this call: tempFile.renameTo(file); We use the * following line, and check for exception... */ try { FileMovingUtil . move ( tempFile , file ) ; } catch ( IOException e ) { throw new JournalException ( "Failed to rename file from '" + tempFile . getPath ( ) + "' to '" + file . getPath ( ) + "'" , e ) ; } open = false ; } catch ( XMLStreamException e ) { throw new JournalException ( e ) ; } catch ( IOException e ) { throw new JournalException ( e ) ; } } }
Write the document trailer clean up everything and rename the file . Set the flag saying we are closed .