static HFileBlock createFromBuff(ByteBuff buf, boolean usesHBaseChecksum, final long offset,
    final int nextBlockOnDiskSize, HFileContext fileContext, ByteBuffAllocator allocator)
    throws IOException {
    buf.rewind();
    final BlockType blockType = BlockType.read(buf);
    final int onDiskSizeWithoutHeader = buf.getInt(Header.ON_DISK_SIZE_WITHOUT_HEADER_INDEX);
    final int uncompressedSizeWithoutHeader =
      buf.getInt(Header.UNCOMPRESSED_SIZE_WITHOUT_HEADER_INDEX);
    final long prevBlockOffset = buf.getLong(Header.PREV_BLOCK_OFFSET_INDEX);
    // This constructor is called when we deserialize a block from cache and when we read a block in
    // from the fs. fileCache is null when deserialized from cache so need to make up one.
    HFileContextBuilder fileContextBuilder =
      fileContext != null ? new HFileContextBuilder(fileContext) : new HFileContextBuilder();
    fileContextBuilder.withHBaseCheckSum(usesHBaseChecksum);
    int onDiskDataSizeWithHeader;
    if (usesHBaseChecksum) {
      byte checksumType = buf.get(Header.CHECKSUM_TYPE_INDEX);
      int bytesPerChecksum = buf.getInt(Header.BYTES_PER_CHECKSUM_INDEX);
      onDiskDataSizeWithHeader = buf.getInt(Header.ON_DISK_DATA_SIZE_WITH_HEADER_INDEX);
      // Use the checksum type and bytes per checksum from header, not from fileContext.
      fileContextBuilder.withChecksumType(ChecksumType.codeToType(checksumType));
      fileContextBuilder.withBytesPerCheckSum(bytesPerChecksum);
    } else {
      fileContextBuilder.withChecksumType(ChecksumType.NULL);
      fileContextBuilder.withBytesPerCheckSum(0);
      // Need to fix onDiskDataSizeWithHeader; there are not checksums after-block-data
      onDiskDataSizeWithHeader = onDiskSizeWithoutHeader + headerSize(usesHBaseChecksum);
    }
    fileContext = fileContextBuilder.build();
    assert usesHBaseChecksum == fileContext.isUseHBaseChecksum();
    return new HFileBlockBuilder().withBlockType(blockType)
      .withOnDiskSizeWithoutHeader(onDiskSizeWithoutHeader)
      .withUncompressedSizeWithoutHeader(uncompressedSizeWithoutHeader)
      .withPrevBlockOffset(prevBlockOffset).withOffset(offset)
      .withOnDiskDataSizeWithHeader(onDiskDataSizeWithHeader)
      .withNextBlockOnDiskSize(nextBlockOnDiskSize).withHFileContext(fileContext)
      .withByteBuffAllocator(allocator).withByteBuff(buf.rewind()).withShared(!buf.hasArray())
      .build();
  }
Creates a block from an existing buffer starting with a header. Rewinds and takes ownership of
the buffer. By definition of rewind, ignores the buffer position, but if you slice the buffer
beforehand, it will rewind to that point.
@param buf Has header, content, and trailing checksums if present.
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java