/** * Creates a lock file. * * @param lockFile the path of the lock file * @return a new {@link LockFile} that can be released later * @throws IOException if creating the lock file fails */ public static LockFile Create(SystemPath lockFile) { lockFile = lockFile ?? throw new ArgumentNullException(nameof(lockFile)); Files.CreateDirectories(lockFile.GetParent()); return(new LockFile(lockFile.ToFile().Create())); }
/** * Acquires an exclusive {@link FileLock} on the {@code file} and opens an {@link OutputStream} to * write to it. The file will be created if it does not exist, or truncated to length 0 if it does * exist. The {@link OutputStream} must be closed to release the lock. * * <p>The locking mechanism should not be used as a concurrency management feature. Rather, this * should be used as a way to prevent concurrent writes to {@code file}. Concurrent attempts to * lock {@code file} will result in {@link OverlappingFileLockException}s. * * @param file the file to write to * @return an {@link OutputStream} that writes to the file * @throws IOException if an I/O exception occurs */ public static Stream NewLockingOutputStream(SystemPath file) { file = file ?? throw new ArgumentNullException(nameof(file)); return(file.ToFile().Create()); }