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
ConstructorDescriptionWrites 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 TypeMethodDescriptionvoid
abort()
When the write operation failed, call this method to leave the original file intact and remove the temporary file.void
close()
void
commit()
void
flush()
Deprecated.Use getTemporaryPath()Until the data is committed, this file captures the written content.void
write
(char[] cbuf, int off, int len) void
write
(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:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in 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)