Class AtomicFiles


  • public final class AtomicFiles
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.BufferedWriter atomicBufferedWriter​(java.nio.file.Path path, java.nio.charset.Charset charset)
      Creates and returns an "atomic" writer for the given path.
      static java.util.concurrent.Callable<java.io.BufferedWriter> atomicWriterFactory​(java.nio.file.Path path, java.nio.charset.Charset charset)
      Creates and returns an "atomic" writer factory for the given path.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • atomicWriterFactory

        public static java.util.concurrent.Callable<java.io.BufferedWriter> atomicWriterFactory​(java.nio.file.Path path,
                                                                                                java.nio.charset.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 java.io.BufferedWriter atomicBufferedWriter​(java.nio.file.Path path,
                                                                  java.nio.charset.Charset charset)
                                                           throws java.io.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:
        java.io.IOException - for any underlying filesystem errors
        Since:
        4.0.0