Package hudson.util

Class AtomicFileWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable

    public class AtomicFileWriter
    extends Writer
    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
    • Constructor Detail

      • 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
        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 flushing
        integrityOnClose - do not force writing to disk when closing
        Throws:
        IOException