code: public int read(long pos, ByteBuffer buf) {
      // since max is buf.remaining() (an int), result is guaranteed to be an int
      int bytesToRead = (int) bytesToRead(pos, buf.remaining());
  
      if (bytesToRead > 0) {
        int remaining = bytesToRead;
  
        int blockIndex = blockIndex(pos);
        byte[] block = blocks[blockIndex];
        int off = offsetInBlock(pos);
  
        remaining -= get(block, off, buf, length(off, remaining));
  
        while (remaining > 0) {
          int index = ++blockIndex;
          block = blocks[index];
          remaining -= get(block, 0, buf, length(remaining));
        }
      }
  
      return bytesToRead;
    }
docs: Reads up to {@code buf.remaining()} bytes starting at position {@code pos} in this file to the
  given buffer. Returns the number of bytes read or -1 if {@code pos} is greater than or equal to
  the size of this file.