public class AtomicFileOutputStream extends FilterOutputStream
FilterOutputStream that writes to a file atomically.
The output file will not show up until it has been entirely written and sync'ed to disk.
It uses a temporary file when it is being written.
The default temporary file has a .tmp suffix.
When the output stream is closed, it is
(1) flushed
(2) sync'ed, and
(3) renamed/moved from the temporary file to the output file.
If the output file already exists, it will be overwritten.
NOTE that on Windows platforms, the output file, if it exists, is deleted
before the temporary file is moved.| Modifier and Type | Field and Description |
|---|---|
static String |
TMP_EXTENSION |
out| Constructor and Description |
|---|
AtomicFileOutputStream(File outFile) |
AtomicFileOutputStream(File outFile,
File tmpFile) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Close the atomic file, but do not "commit" the temporary file
on top of the destination.
|
void |
close() |
static File |
getTemporaryFile(File outFile) |
boolean |
isClosed() |
flush, write, write, writepublic static final String TMP_EXTENSION
public AtomicFileOutputStream(File outFile) throws FileNotFoundException
FileNotFoundExceptionpublic AtomicFileOutputStream(File outFile, File tmpFile) throws FileNotFoundException
FileNotFoundExceptionpublic boolean isClosed()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class FilterOutputStreamIOExceptionpublic void abort()
Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.