public static BufferedWriter createAtomicBufferedWriter(Path path, Charset charset) throws IOException { path = path.toAbsolutePath(); Path writePath = getTemporaryPath(path.getParent(), path.getFileName().toString()); if (Files.exists(path)) { Files.copy(path, writePath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); } BufferedWriter output = Files.newBufferedWriter(writePath, charset); return new BufferedWriter(new AtomicFileWriter(writePath, path, output)); }
/** * Creates and returns an "atomic" writer for the given path. * * @param path The path * @param charset The charset to be used by the writer * @return The writer factory */ @NonNull public static BufferedWriter createAtomicBufferedWriter(@NonNull Path path, @NonNull Charset charset) throws IOException { path = path.toAbsolutePath(); Path writePath = getTemporaryPath(path.getParent(), path.getFileName().toString()); if (Files.exists(path)) { Files.copy(path, writePath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); } BufferedWriter output = Files.newBufferedWriter(writePath, charset); return new BufferedWriter(new AtomicFileWriter(writePath, path, output)); }
/** * Creates and returns an "atomic" writer for the given path. * * @param path The path * @param charset The charset to be used by the writer * @return The writer factory */ @NonNull public static BufferedWriter createAtomicBufferedWriter(@NonNull Path path, @NonNull Charset charset) throws IOException { path = path.toAbsolutePath(); Path writePath = getTemporaryPath(path.getParent(), path.getFileName().toString()); if (Files.exists(path)) { Files.copy(path, writePath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); } BufferedWriter output = Files.newBufferedWriter(writePath, charset); return new BufferedWriter(new AtomicFileWriter(writePath, path, output)); }