Class AtomicFiles


  • public final class AtomicFiles
    extends Object
    A utility for creating "atomic" file writers.

    An atomic writer copies any existing file at the given path to a temporary location, then writes to the same temporary location, before moving the file back to the desired output path once the write is fully complete.

    Since:
    4.0.0
    • Method Detail

      • atomicWriterFactory

        public static Callable<BufferedWriteratomicWriterFactory​(Path path,
                                                                   Charset charset)
        Creates and returns an "atomic" writer factory for the given path.
        Parameters:
        path - path the complete file should be written to
        charset - the charset to be used by the writer
        Returns:
        a new writer factory
        Since:
        4.0.0
      • atomicBufferedWriter

        public static BufferedWriter atomicBufferedWriter​(Path path,
                                                          Charset charset)
                                                   throws IOException
        Creates and returns an "atomic" writer for the given path.
        Parameters:
        path - the path
        charset - the charset to be used by the writer
        Returns:
        a new writer factory
        Throws:
        IOException - for any underlying filesystem errors
        Since:
        4.0.0