Saves file in as crash-safe a manner as possible.
In order to prevent system or muCommander failures to corrupt configuration files, the BackupOutputStream implements the following algorithm:
- Write its content to a backup file instead of the requested file
- When close is called, copy the content of the backup file over the original file
This way, if a crash was to happen while configuration files are being saved, either of the following will happen:
- The backup file is not properly saved, but the original configuration is left untouched. We have lost some information (modifications since last save) but not all.
- The original file is not properly saved, but the backup file is correct. This is easy to check, as the backup and original file should always have the same size. If they don't, then the backup file should be used rather than the original one.
Files that have been saved by this class should be read with {@link BackupInputStream}in order to make sure that an uncorrupt version of them is loaded.
The BackupOutputStream
monitors all of its own I/O operations. If an error occurs, then the backup operation will not be performed when {@link #close()} is called. It's possible to force the backup operation byusing the {@link #close(boolean)} method.
@see BackupInputStream
@author Nicolas Rinaudo