Package org.apache.zookeeper.common
Class AtomicFileOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.apache.zookeeper.common.AtomicFileOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class AtomicFileOutputStream extends java.io.FilterOutputStream
A FileOutputStream that has the property that it will only show up at its destination once it has been entirely written and flushed to disk. While being written, it will use a .tmp suffix. When the output stream is closed, it is flushed, fsynced, and will be moved into place, overwriting any file that already exists at that location. NOTE: on Windows platforms, it will not atomically replace the target file - instead the target file is deleted before this one is moved into place.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
TMP_EXTENSION
-
Constructor Summary
Constructors Constructor Description AtomicFileOutputStream(java.io.File f)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Close the atomic file, but do not "commit" the temporary file on top of the destination.void
close()
void
write(byte[] b, int off, int len)
The default write method in FilterOutputStream does not call the write method of its underlying input stream with the same arguments.
-
-
-
Field Detail
-
TMP_EXTENSION
public static final java.lang.String TMP_EXTENSION
- See Also:
- Constant Field Values
-
-
Method Detail
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
The default write method in FilterOutputStream does not call the write method of its underlying input stream with the same arguments. Instead it writes the data byte by byte, override it here to make it more efficient.- Overrides:
write
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
abort
public void abort()
Close the atomic file, but do not "commit" the temporary file on top of the destination. This should be used if there is a failure in writing.
-
-