Package org.apache.zookeeper.common
Class AtomicFileOutputStream
- java.lang.Object
- 
- java.io.OutputStream
- 
- java.io.FilterOutputStream
- 
- org.apache.zookeeper.common.AtomicFileOutputStream
 
 
 
- 
- All Implemented Interfaces:
- Closeable,- Flushable,- AutoCloseable
 
 public class AtomicFileOutputStream extends 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 SummaryFields Modifier and Type Field Description static StringTMP_EXTENSION- 
Fields inherited from class java.io.FilterOutputStreamout
 
- 
 - 
Constructor SummaryConstructors Constructor Description AtomicFileOutputStream(File f)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Close the atomic file, but do not "commit" the temporary file on top of the destination.voidclose()voidwrite(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.- 
Methods inherited from class java.io.FilterOutputStreamflush, write, write
 
- 
 
- 
- 
- 
Field Detail- 
TMP_EXTENSIONpublic static final String TMP_EXTENSION - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
AtomicFileOutputStreampublic AtomicFileOutputStream(File f) throws FileNotFoundException - Throws:
- FileNotFoundException
 
 
- 
 - 
Method Detail- 
writepublic void write(byte[] b, int off, int len) throws IOExceptionThe 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:
- writein class- FilterOutputStream
- Throws:
- IOException
 
 - 
closepublic void close() throws IOException- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- FilterOutputStream
- Throws:
- IOException
 
 - 
abortpublic 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.
 
- 
 
-