/** * Run function <code>f</code> having exclusive read/write access to the given file. * <p> * Please note that the implementation uses Java NIO {@link java.nio.channels.FileLock} which only guarantees that two * Java processes cannot interfere with each other. * <p> * The implementation blocks until a lock can be acquired. * * @throws NotFoundException * if the path to the file, to create a lock for, does not exist * @throws IOException * if the file lock can not be created due to access limitations */ public static synchronized <A> A locked(File file, Function<File, A> f) throws NotFoundException, IOException { final Effect0 key = acquireLock(file); try { return f.apply(file); } finally { key.apply(); } }