@Override
  public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
    checkNotNull(target);
    Util.checkNotNegative(position, "position");
    Util.checkNotNegative(count, "count");
    checkOpen();
    checkReadable();

    long transferred = 0; // will definitely either be assigned or an exception will be thrown

    // no need to synchronize here; this method does not make use of the channel's position
    boolean completed = false;
    try {
      if (!beginBlocking()) {
        return 0; // AsynchronousCloseException will be thrown
      }
      file.readLock().lockInterruptibly();
      try {
        transferred = file.transferTo(position, count, target);
        file.setLastAccessTime(fileSystemState.now());
        completed = true;
      } finally {
        file.readLock().unlock();
      }
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    } finally {
      endBlocking(completed);
    }

    return transferred;
  }
@Test
  public void testTransferTo() throws IOException {
    RegularFile file = regularFile(10);
    FileChannel channel = channel(file, READ);

    ByteBufferChannel writeChannel = new ByteBufferChannel(buffer("1234567890"));
    assertEquals(10, channel.transferTo(0, 100, writeChannel));
    assertEquals(0, channel.position());
  }