public static boolean stampVersion ( JsonDBConfig dbConfig , File f , String version ) { FileOutputStream fos = null ; OutputStreamWriter osr = null ; BufferedWriter writer = null ; try { fos = new FileOutputStream ( f ) ; osr = new OutputStreamWriter ( fos , dbConfig . getCharset ( ) ) ; writer = new BufferedWriter ( osr ) ; String versionData = dbConfig . getObjectMapper ( ) . writeValueAsString ( new SchemaVersion ( version ) ) ; writer . write ( versionData ) ; writer . newLine ( ) ; } catch ( JsonProcessingException e ) { logger . error ( "Failed to serialize SchemaVersion to Json string" , e ) ; return false ; } catch ( IOException e ) { logger . error ( "Failed to write SchemaVersion to the new .json file {}" , f , e ) ; return false ; } finally { try { writer . close ( ) ; } catch ( IOException e ) { logger . error ( "Failed to close BufferedWriter for new collection file {}" , f , e ) ; } try { osr . close ( ) ; } catch ( IOException e ) { logger . error ( "Failed to close OutputStreamWriter for new collection file {}" , f , e ) ; } try { fos . close ( ) ; } catch ( IOException e ) { logger . error ( "Failed to close FileOutputStream for new collection file {}" , f , e ) ; } } return true ; }
Utility to stamp the version into a newly created . json File This method is expected to be invoked on a newly created . json file before it is usable . So no locking code required .