private void writeLocation() { if ( pathname == null ) return; // Does not need synchronizing. IOX.safeWrite(pathname, out->out.write(value)); } }
/** Atomically write the file */ public void write(IOConsumer<OutputStream> action) { if ( haveWritten ) throw new RuntimeIOException("FileEntry has already been written: "+datafile); IOX.safeWrite(datafile, tmpfile, action); haveWritten = true; }
/** Write a file safely - the change happens (the function returns true) or * something went wrong (the function throws a runtime exception) and the file is not changed. * Note that the tempfile must be in the same direct as the actual file so an OS-atomic rename can be done. */ public static boolean safeWrite(Path file, IOConsumer<OutputStream> writerAction) { Path tmp = createTempFile(file.getParent(), file.getFileName().toString(), ".tmp"); return safeWrite(file, tmp, writerAction); }