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
BufferedFileWriter
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
-
-
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 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()
Deprecated.Use getTemporaryPath()Path
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
write(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:
write
in classWriter
- Throws:
IOException
-
write
public void write(String str, int off, int len) throws IOException
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
public void write(char[] cbuf, int off, int len) throws IOException
- Specified by:
write
in classWriter
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
abort
public void abort() throws IOException
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
public void commit() throws IOException
- Throws:
IOException
-
finalize
protected void finalize() throws Throwable
-
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
-
-