Package hudson.util
Class AtomicFileWriter
- java.lang.Object
-
- java.io.Writer
-
- hudson.util.AtomicFileWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class AtomicFileWriter extends Writer
BufferedFileWriterthat 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
-
-
Constructor Summary
Constructors Constructor Description AtomicFileWriter(File f)Writes 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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidabort()When the write operation failed, call this method to leave the original file intact and remove the temporary file.voidclose()voidcommit()voidflush()FilegetTemporaryFile()Deprecated.Use getTemporaryPath()PathgetTemporaryPath()Until the data is committed, this file captures the written content.voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(String str, int off, int len)
-
-
-
Constructor Detail
-
AtomicFileWriter
public AtomicFileWriter(File f) throws IOException
Writes with UTF-8 encoding.- Throws:
IOException
-
AtomicFileWriter
@Deprecated public AtomicFileWriter(@NonNull File f, @Nullable String encoding) throws IOException
Deprecated.- Parameters:
encoding- File encoding to write. If null, platform default encoding is chosen.- Throws:
IOException
-
AtomicFileWriter
public AtomicFileWriter(@NonNull Path destinationPath, @NonNull Charset charset) throws IOException- 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 Detail
-
write
public void write(int c) throws IOException- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(String str, int off, int len) throws IOException
- Overrides:
writein classWriter- Throws:
IOException
-
write
public void write(char[] cbuf, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
abort
public void abort() throws IOExceptionWhen 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
public void commit() throws IOException- Throws:
IOException
-
getTemporaryFile
@Deprecated public File getTemporaryFile()
Deprecated.Use getTemporaryPath()Until the data is committed, this file captures the written content.
-
getTemporaryPath
public Path getTemporaryPath()
Until the data is committed, this file captures the written content.- Since:
- 2.93
-
-