private File createFile(
      JimfsPath path,
      Supplier<? extends File> fileCreator,
      boolean failIfExists,
      FileAttribute<?>... attrs)
      throws IOException {
    checkNotNull(path);
    checkNotNull(fileCreator);

    store.writeLock().lock();
    try {
      DirectoryEntry entry = lookUp(path, Options.NOFOLLOW_LINKS);

      if (entry.exists()) {
        if (failIfExists) {
          throw new FileAlreadyExistsException(path.toString());
        }

        // currently can only happen if getOrCreateFile doesn't find the file with the read lock
        // and then the file is created between when it releases the read lock and when it
        // acquires the write lock; so, very unlikely
        return entry.file();
      }

      Directory parent = entry.directory();

      File newFile = fileCreator.get();
      store.setInitialAttributes(newFile, attrs);
      parent.link(path.name(), newFile);
      parent.setLastModifiedTime(now());
      return newFile;
    } finally {
      store.writeLock().unlock();
    }
  }
Creates a new file at the given path if possible, using the given supplier to create the file.
Returns the new file. If {@code allowExisting} is {@code true} and a file already exists at the
given path, returns that file. Otherwise, throws {@link FileAlreadyExistsException}.
jimfs/src/main/java/com/google/common/jimfs/FileSystemView.java