/**
   * Open/creates file, returning AsynchronousFileChannel to access the file
   *
   * @param pathForWindows The path of the file to open/create
   * @param pathToCheck The path used for permission checks (if security manager)
   * @param pool The thread pool that the channel is associated with
   */
  static AsynchronousFileChannel newAsynchronousFileChannel(
      String pathForWindows,
      String pathToCheck,
      Set<? extends OpenOption> options,
      long pSecurityDescriptor,
      ThreadPool pool)
      throws IOException {
    Flags flags = Flags.toFlags(options);

    // Overlapped I/O required
    flags.overlapped = true;

    // default is reading
    if (!flags.read && !flags.write) {
      flags.read = true;
    }

    // validation
    if (flags.append) throw new UnsupportedOperationException("APPEND not allowed");

    // open file for overlapped I/O
    FileDescriptor fdObj;
    try {
      fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor);
    } catch (WindowsException x) {
      x.rethrowAsIOException(pathForWindows);
      return null;
    }

    // create the AsynchronousFileChannel
    try {
      return WindowsAsynchronousFileChannelImpl.open(fdObj, flags.read, flags.write, pool);
    } catch (IOException x) {
      // IOException is thrown if the file handle cannot be associated
      // with the completion port. All we can do is close the file.
      long handle = fdAccess.getHandle(fdObj);
      CloseHandle(handle);
      throw x;
    }
  }