AtomicFileOperations { public static void atomicWriteString(final File destinationFile, final String string) throws SyncFailedException, IOException { atomicWriteBytes(destinationFile, string.getBytes(StandardCharsets.UTF_8)); }  static void atomicWriteSignedMessage(final File destinationFile, final SignedMessage signedMessage); static void atomicWriteString(final File destinationFile, final String string); static void atomicWriteBytes(final File destinationFile, final byte[] data); static SignedMessage readSignedMessage(final File saveFile);  }
@Test public void testAtomicWrite() throws IOException { final File tempFile = File.createTempFile("test-file", UUID.randomUUID().toString()); tempFile.deleteOnExit(); for (int i = 0; i < 10; i++) { final String str = new String("hello-" + i); long start = System.nanoTime(); AtomicFileOperations.atomicWriteString(tempFile, str); long end = System.nanoTime(); System.out.println("Atomically wrote file in: " + (end - start) + " ns"); System.out.println("Wrote to: " + tempFile.getAbsolutePath()); } tempFile.delete(); }