@Override
  public int read(ByteBuffer dst) throws IOException {
    checkNotNull(dst);
    checkOpen();
    checkReadable();

    int read = 0; // will definitely either be assigned or an exception will be thrown

    synchronized (this) {
      boolean completed = false;
      try {
        if (!beginBlocking()) {
          return 0; // AsynchronousCloseException will be thrown
        }
        file.readLock().lockInterruptibly();
        try {
          read = file.read(position, dst);
          if (read != -1) {
            position += read;
          }
          file.setLastAccessTime(fileSystemState.now());
          completed = true;
        } finally {
          file.readLock().unlock();
        }
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      } finally {
        endBlocking(completed);
      }
    }

    return read;
  }
@Test
  public void testReadNegative() throws IOException {
    FileChannel channel = channel(regularFile(0), READ, WRITE);

    try {
      channel.read(buffer("111"), -1);
      fail();
    } catch (IllegalArgumentException expected) {
    }

    ByteBuffer[] bufs = {buffer("111"), buffer("111")};
    try {
      channel.read(bufs, -1, 10);
      fail();
    } catch (IndexOutOfBoundsException expected) {
    }

    try {
      channel.read(bufs, 0, -1);
      fail();
    } catch (IndexOutOfBoundsException expected) {
    }
  }