code: public long transferFrom(ReadableByteChannel src, long pos, long count) throws IOException {
      prepareForWrite(pos, 0); // don't assume the full count bytes will be written
  
      if (count == 0) {
        return 0;
      }
  
      long remaining = count;
  
      int blockIndex = blockIndex(pos);
      byte[] block = blockForWrite(blockIndex);
      int off = offsetInBlock(pos);
  
      ByteBuffer buf = ByteBuffer.wrap(block, off, length(off, remaining));
  
      long currentPos = pos;
      int read = 0;
      while (buf.hasRemaining()) {
        read = src.read(buf);
        if (read == -1) {
          break;
        }
  
        currentPos += read;
        remaining -= read;
      }
  
      // update size before trying to get next block in case the disk is out of space
      if (currentPos > size) {
        size = currentPos;
      }
  
      if (read != -1) {
        outer:
        while (remaining > 0) {
          block = blockForWrite(++blockIndex);
  
          buf = ByteBuffer.wrap(block, 0, length(remaining));
          while (buf.hasRemaining()) {
            read = src.read(buf);
            if (read == -1) {
              break outer;
            }
  
            currentPos += read;
            remaining -= read;
          }
  
          if (currentPos > size) {
            size = currentPos;
          }
        }
      }
  
      if (currentPos > size) {
        size = currentPos;
      }
  
      return currentPos - pos;
    }
docs: Transfers up to {@code count} bytes from the given channel to this file starting at position
  {@code pos}. Returns the number of bytes transferred. If {@code pos} is greater than the
  current size of this file, the file is truncated up to size {@code pos} before writing.
  
  @throws IOException if the file needs more blocks but the disk is full or if reading from src
  throws an exception