public final class AtomicFile extends Object
Atomic file guarantees file integrity by ensuring that a file has been completely written and sync'd to disk before removing its backup. As long as the backup file exists, the original file is considered to be invalid (left over from a previous attempt to write the file).
Atomic file does not confer any file locking semantics. Do not use this class when the file may be accessed or modified concurrently by multiple threads or processes. The caller is responsible for ensuring appropriate mutual exclusion invariants whenever it accesses the file.
Constructor and Description |
---|
AtomicFile(File baseName) |
Modifier and Type | Method and Description |
---|---|
void |
delete() |
boolean |
exists() |
void |
failWrite(FileOutputStream str) |
void |
finishWrite(FileOutputStream str) |
File |
getBaseFile() |
FileOutputStream |
openAppend() |
FileInputStream |
openRead() |
byte[] |
readFully() |
FileOutputStream |
startWrite() |
void |
truncate() |
public AtomicFile(File baseName)
public File getBaseFile()
public FileOutputStream startWrite() throws IOException
IOException
public void finishWrite(FileOutputStream str)
public void failWrite(FileOutputStream str)
public FileOutputStream openAppend() throws IOException
IOException
public void truncate() throws IOException
IOException
public boolean exists()
public void delete()
public FileInputStream openRead() throws FileNotFoundException
FileNotFoundException
public byte[] readFully() throws IOException
IOException