private static Pair<String, String> readFromFile( FileSystemAbstraction fs, File file, MigrationStatus expectedSate ) { try ( BufferedReader reader = new BufferedReader( fs.openAsReader( file, StandardCharsets.UTF_8 ) ) ) { String state = reader.readLine().trim(); if ( expectedSate != null && !expectedSate.name().equals( state ) ) { throw new IllegalStateException( "Not in the expected state, expected=" + expectedSate.name() + ", actual=" + state ); } String info = reader.readLine().trim(); return Pair.of( state, info ); } catch ( FileNotFoundException e ) { return null; } catch ( IOException e ) { throw new RuntimeException( e ); } }
public void setMigrationStatus( FileSystemAbstraction fs, File stateFile, String info ) { if ( fs.fileExists( stateFile ) ) { try { fs.truncate( stateFile, 0 ); } catch ( IOException e ) { throw new RuntimeException( e ); } } try ( Writer writer = fs.openAsWriter( stateFile, StandardCharsets.UTF_8, false ) ) { writer.write( name() ); writer.write( '\n' ); writer.write( info ); writer.flush(); } catch ( IOException e ) { throw new RuntimeException( e ); } } }
private static Pair<String, String> readFromFile( FileSystemAbstraction fs, File file, MigrationStatus expectedSate ) { try ( BufferedReader reader = new BufferedReader( fs.openAsReader( file, StandardCharsets.UTF_8 ) ) ) { String state = reader.readLine().trim(); if ( expectedSate != null && !expectedSate.name().equals( state ) ) { throw new IllegalStateException( "Not in the expected state, expected=" + expectedSate.name() + ", actual=" + state ); } String info = reader.readLine().trim(); return Pair.of( state, info ); } catch ( FileNotFoundException e ) { return null; } catch ( IOException e ) { throw new RuntimeException( e ); } }
public void setMigrationStatus( FileSystemAbstraction fs, File stateFile, String info ) { if ( fs.fileExists( stateFile ) ) { try { fs.truncate( stateFile, 0 ); } catch ( IOException e ) { throw new RuntimeException( e ); } } try ( Writer writer = fs.openAsWriter( stateFile, StandardCharsets.UTF_8, false ) ) { writer.write( name() ); writer.write( '\n' ); writer.write( info ); writer.flush(); } catch ( IOException e ) { throw new RuntimeException( e ); } } }