public void write(JobStatus status, File file) throws IOException
    {
        File tempFile = File.createTempFile(file.getName(), ".tmp");

        try (FileOutputStream stream = FileUtils.openOutputStream(tempFile)) {
            write(status, stream);
        }

        // Copy the file to its final destination
        file.mkdirs();
        for (int i = 0; i < 10; ++i) {
            try {
                Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);

                // Stop the retry loop if it succeeded
                break;
            } catch (FileAlreadyExistsException e) {
                // Yes it sounds pretty weird but it can happen so we try 10 times before giving up
                // Wait a bit before retrying
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ei) {
                    throw e;
                }
            }
        }
    }
public void write ( JobStatus status , File file ) throws IOException { File tempFile = File . createTempFile ( file . getName ( ) , ".tmp" ) ; try ( FileOutputStream stream = FileUtils . openOutputStream ( tempFile ) ) { write ( status , stream ) ; } file . mkdirs ( ) ; for ( int i = 0 ; i < 10 ; ++ i ) { try { Files . move ( tempFile . toPath ( ) , file . toPath ( ) , StandardCopyOption . REPLACE_EXISTING ) ; break ; } catch ( FileAlreadyExistsException e ) { try { Thread . sleep ( 1000 ) ; } catch ( InterruptedException ei ) { throw e ; } } } }
@param status the status to serialize
@param file the file to serialize the status to
@throws IOException when failing to serialize the status