synchronized private void saveMetadata ( ) throws StageException { // 0) Validate pre-conditions if ( Files . exists ( newMetadataFile ) ) { throw new StageException ( BlobStoreError . BLOB_STORE_0010 ) ; } // 1) New content is written into a new temporary file. try ( OutputStream os = Files . newOutputStream ( newMetadataFile , StandardOpenOption . CREATE , StandardOpenOption . TRUNCATE_EXISTING ) ) { jsonMapper . writeValue ( os , metadata ) ; } catch ( IOException e ) { throw new StageException ( BlobStoreError . BLOB_STORE_0001 , e . toString ( ) , e ) ; } // 2) Old metadata is dropped try { if ( Files . exists ( metadataFile ) ) { Files . delete ( metadataFile ) ; } } catch ( IOException e ) { throw new StageException ( BlobStoreError . BLOB_STORE_0011 , e . toString ( ) , e ) ; } // 3) Rename from new to old is done try { Files . move ( newMetadataFile , metadataFile ) ; } catch ( IOException e ) { throw new StageException ( BlobStoreError . BLOB_STORE_0012 , e . toString ( ) , e ) ; } }
Commit metadata content to a file to disk .