@Override
  public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException {
    checkNotNull(src);
    Util.checkNotNegative(position, "position");
    Util.checkNotNegative(count, "count");
    checkOpen();
    checkWritable();

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

    if (append) {
      // synchronize because appending does update the channel's position
      synchronized (this) {
        boolean completed = false;
        try {
          if (!beginBlocking()) {
            return 0; // AsynchronousCloseException will be thrown
          }

          file.writeLock().lockInterruptibly();
          try {
            position = file.sizeWithoutLocking();
            transferred = file.transferFrom(src, position, count);
            this.position = position + transferred;
            file.setLastModifiedTime(fileSystemState.now());
            completed = true;
          } finally {
            file.writeLock().unlock();
          }
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        } finally {
          endBlocking(completed);
        }
      }
    } else {
      // don't synchronize because the channel's position is not involved
      boolean completed = false;
      try {
        if (!beginBlocking()) {
          return 0; // AsynchronousCloseException will be thrown
        }
        file.writeLock().lockInterruptibly();
        try {
          transferred = file.transferFrom(src, position, count);
          file.setLastModifiedTime(fileSystemState.now());
          completed = true;
        } finally {
          file.writeLock().unlock();
        }
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      } finally {
        endBlocking(completed);
      }
    }

    return transferred;
  }
@Test
  public void testTransferFrom() throws IOException {
    RegularFile file = regularFile(0);
    FileChannel channel = channel(file, WRITE);

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