public synchronized void save(T o) throws IOException {
  String fileName=prefix + nextWriteGen;
  IndexOutput out=dir.createOutput(fileName,IOContext.DEFAULT);
  boolean success=false;
  try {
    saveOne(out,o);
    success=true;
  }
  finally {
    if (success == false) {
      IOUtils.closeWhileHandlingException(out);
      try {
        dir.deleteFile(fileName);
      }
 catch (      Exception e) {
      }
    }
 else {
      IOUtils.close(out);
    }
  }
  dir.sync(Collections.singletonList(fileName));
  if (nextWriteGen > 0 && canDelete(nextWriteGen - 1)) {
    String oldFileName=prefix + (nextWriteGen - 1);
    try {
      dir.deleteFile(oldFileName);
    }
 catch (    FileNotFoundException|NoSuchFileException nsfe) {
    }
  }
  nextWriteGen++;
}

public synchronized void save ( T o ) throws IOException { String fileName = prefix + nextWriteGen ; IndexOutput out = dir . createOutput ( fileName , IOContext . DEFAULT ) ; boolean success = false ; try { saveOne ( out , o ) ; success = true ; } finally { if ( success == false ) { IOUtils . closeWhileHandlingException ( out ) ; try { dir . deleteFile ( fileName ) ; } catch ( Exception e ) { } } else { IOUtils . close ( out ) ; } } dir . sync ( Collections . singletonList ( fileName ) ) ; if ( nextWriteGen > 0 && canDelete ( nextWriteGen - 1 ) ) { String oldFileName = prefix + ( nextWriteGen - 1 ) ; try { dir . deleteFile ( oldFileName ) ; } catch ( FileNotFoundException | NoSuchFileException nsfe ) { } } nextWriteGen ++ ; }
save the object to the next write generation .
