public static void write ( final byte [ ] data , final Path path ) throws IOException { try ( final SafeOutputStream out = createAtomicFile ( path ) ) { out . write ( ByteBuffer . wrap ( data ) ) ; out . commit ( ) ; } }
Write the bytes to a temporary file fsync the file then atomically rename to the target path . On error it will make a best - effort to erase the temporary file .