/**
   * @param file The file to open
   * @param mode Either "rw" or "r", depending on whether this file is read only
   * @param bufferSize The size of the buffer used to manually buffer I/O If -1 the default buffer
   *     size is used, which depends on how {@link DirectIoLib} is implemented.
   * @throws IOException
   */
  public DirectRandomAccessFile(File file, String mode, int bufferSize) throws IOException {

    boolean readOnly = false;
    if (mode.equals("r")) {
      readOnly = true;
    } else if (!mode.equals("rw")) {
      throw new IllegalArgumentException("only r and rw modes supported");
    }

    if (readOnly && !file.isFile()) {
      throw new FileNotFoundException("couldn't find file " + file);
    }

    this.channel =
        bufferSize != -1
            ? DirectIoByteChannelAligner.open(file, bufferSize, readOnly)
            : DirectIoByteChannelAligner.open(file, readOnly);
  }