public class AtomicFileWriter extends Writer
FileWriter that supports atomic operations.
The write operation is atomic when used for overwriting; it either leaves the original file intact, or it completely rewrites it with new contents.
| Constructor and Description |
|---|
AtomicFileWriter(File f)
Writes with UTF-8 encoding.
|
AtomicFileWriter(File f,
String encoding) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
When the write operation failed, call this method to
leave the original file intact and remove the temporary file.
|
void |
close() |
void |
commit() |
protected void |
finalize() |
void |
flush() |
File |
getTemporaryFile()
Until the data is committed, this file captures
the written content.
|
void |
write(char[] cbuf,
int off,
int len) |
void |
write(int c) |
void |
write(String str,
int off,
int len) |
public AtomicFileWriter(File f) throws IOException
IOExceptionpublic AtomicFileWriter(File f, String encoding) throws IOException
encoding - File encoding to write. If null, platform default encoding is chosen.IOExceptionpublic void write(int c)
throws IOException
write in class WriterIOExceptionpublic void write(String str, int off, int len) throws IOException
write in class WriterIOExceptionpublic void write(char[] cbuf,
int off,
int len)
throws IOException
write in class WriterIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class WriterIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class WriterIOExceptionpublic void abort()
throws IOException
commit() is called, to simplify coding.IOExceptionpublic void commit()
throws IOException
IOExceptionprotected void finalize()
throws Throwable
public File getTemporaryFile()
Copyright © 2019. All rights reserved.