Class SafeFileOutputStream
java.lang.Object
java.io.OutputStream
com.inductiveautomation.ignition.common.util.SafeFileOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
A FileOutputStream that implements a two-stage write process, and additionaly copies any existing file to a backup location. This ensures that no matter what (software or hardware failures), there is always a valid (non-corrupt) copy of the destination file. More formally, the logic is as follows.
- As write() is called on the SafeFileOutputStream instance, information is written to a temporary file, obtained by File.createTempFile().
- When close() is called, the destination file (if it exists), is renamed to the backup file
- Then the temp file is renamed to the destination file
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
SafeFileOutputStream
- Throws:
IOException
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-