@CanIgnoreReturnValue
  public int write(long pos, ByteBuffer buf) throws IOException {
    int len = buf.remaining();

    prepareForWrite(pos, len);

    if (len == 0) {
      return 0;
    }

    int blockIndex = blockIndex(pos);
    byte[] block = blocks[blockIndex];
    int off = offsetInBlock(pos);

    put(block, off, buf);

    while (buf.hasRemaining()) {
      block = blocks[++blockIndex];

      put(block, 0, buf);
    }

    long endPos = pos + len;
    if (endPos > size) {
      size = endPos;
    }

    return len;
  }
Writes all available bytes from buffer {@code buf} to this file starting at position {@code
pos}. {@code pos} may be greater than the current size of this file, in which case this file is
resized and all bytes between the current size and {@code pos} are set to 0. Returns the number
of bytes written.

@throws IOException if the file needs more blocks but the disk is full
jimfs/src/main/java/com/google/common/jimfs/RegularFile.java