/**
   * @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);
  }
 @Override
 public void write(int v) throws IOException {
   channel.write(v);
 }
 @Override
 public void close() throws IOException {
   channel.close();
 }
 /** @return The current position in the file */
 public long getFilePointer() {
   return channel.position();
 }
 /** @return The current length of the file */
 public long length() {
   return channel.size();
 }
 /**
  * Seeks to position <tt>pos</tt> within the file.
  *
  * @param pos The position to which to seek
  * @throws IOException
  */
 public void seek(long pos) throws IOException {
   channel.position(pos);
 }
 /**
  * Bulk read bytes from channel into dst.
  *
  * @param dst The destination byte array
  * @throws IOException
  */
 public void read(byte[] dst) throws IOException {
   channel.readBytes(dst, 0, dst.length);
 }
 /**
  * Bulk read bytes from channel into dst.
  *
  * @param dst The destination byte array
  * @param offset The offset within dst to start reading
  * @param length The number of bytes to read
  * @throws IOException
  */
 public void read(byte[] dst, int offset, int length) throws IOException {
   channel.readBytes(dst, offset, length);
 }
 /**
  * Reads one byte, and returns cast as an int.
  *
  * @return one byte from the underlying channel
  * @throws IOException
  */
 public int read() throws IOException {
   return channel.read();
 }
 @Override
 public void write(byte[] src, int offset, int length) throws IOException {
   channel.writeBytes(src, offset, length);
 }