Package hudson.util
Class AtomicFileWriter
java.lang.Object
java.io.Writer
hudson.util.AtomicFileWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
Buffered
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.
- Author:
- Kohsuke Kawaguchi
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionWrites with UTF-8 encoding.AtomicFileWriter(File f, String encoding) Deprecated.AtomicFileWriter(Path destinationPath, Charset charset) AtomicFileWriter(Path destinationPath, Charset charset, boolean integrityOnFlush, boolean integrityOnClose) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()When the write operation failed, call this method to leave the original file intact and remove the temporary file.voidclose()voidcommit()voidflush()Deprecated.Use getTemporaryPath()Until the data is committed, this file captures the written content.voidwrite(char[] cbuf, int off, int len) voidwrite(int c) void
-
Constructor Details
-
AtomicFileWriter
Writes with UTF-8 encoding.- Throws:
IOException
-
AtomicFileWriter
Deprecated.- Parameters:
encoding- File encoding to write. If null, platform default encoding is chosen.- Throws:
IOException
-
AtomicFileWriter
- Parameters:
destinationPath- the destination path where to write the content when committed.charset- File charset to write.- Throws:
IOException
-
AtomicFileWriter
@Deprecated public AtomicFileWriter(@NonNull Path destinationPath, @NonNull Charset charset, boolean integrityOnFlush, boolean integrityOnClose) throws IOException Deprecated.DO NOT USE THIS METHOD, OR YOU WILL LOSE DATA INTEGRITY.- Parameters:
destinationPath- the destination path where to write the content when committed.charset- File charset to write.integrityOnFlush- do not force writing to disk when flushingintegrityOnClose- do not force writing to disk when closing- Throws:
IOException
-
-
Method Details
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Specified by:
writein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
abort
When the write operation failed, call this method to leave the original file intact and remove the temporary file. This method can be safely invoked from the "finally" block, even after thecommit()is called, to simplify coding.- Throws:
IOException
-
commit
- Throws:
IOException
-
getTemporaryFile
Deprecated.Use getTemporaryPath()Until the data is committed, this file captures the written content. -
getTemporaryPath
Until the data is committed, this file captures the written content.- Since:
- 2.93
-
AtomicFileWriter(Path, Charset)