@Override
  public int transferTo(ByteBuf buf) throws IOException {
    if (mFileSize <= mPos) {
      return -1;
    }
    int bytesToTransfer =
        (int) Math.min(buf.writableBytes(), mFileSize - mPos);
    ReadTargetBuffer targetBuffer = new NettyBufTargetBuffer(buf);
    int bytesRead = mPositionReader.read(mPos, targetBuffer, bytesToTransfer);
    if (bytesRead > 0) {
      mPos += bytesRead;
    }
    return bytesRead;
  }
@Test
  public void transferTo() throws IOException {
    int testNum = Math.min(mFileLen, mMinTestNum);
    for (int i = 0; i < testNum; i++) {
      int offset = mRandom.nextInt(mFileLen);
      mPagedFileReader.setPosition(offset);
      ByteBuf byteBuf = Unpooled.buffer(mFileLen);

      int bytesRead = mPagedFileReader.transferTo(byteBuf);
      byte[] realBytesArray = new byte[bytesRead];
      System.arraycopy(mTestData, offset, realBytesArray, 0, bytesRead);
      byte[] bytesArray = new byte[byteBuf.readableBytes()];
      byteBuf.readBytes(bytesArray);
      assertTrue(bytesRead > 0);
      assertArrayEquals(realBytesArray, bytesArray);
    }
  }