} finally {
IOUtils.closeQuietly(out);
}
} catch (IOException ex) {
FileUtils.deleteQuietly(tmpFile);
throw new StorageException(ex);
}
// Does the file exist?
// If so, make a backup
File backupFile = new File(file.getParentFile(), file.getName() + ".bak");
if (file.exists()) {
try {
FileUtils.copyFile(file, backupFile);
} catch (IOException ex) {
throw new StorageException(ex);
}
}
// Copy the temporary file to its final name
try {
FileUtils.copyFile(tmpFile, file);
} catch (IOException ex) {
throw new StorageException(ex);
}
// Tidy up
if (tmpFile.exists()) {
FileUtils.deleteQuietly(tmpFile);
}