private ByteBuff allocateBufferForUnpacking() {
    int headerSize = headerSize();
    int capacityNeeded = headerSize + uncompressedSizeWithoutHeader;

    ByteBuff source = bufWithoutChecksum.duplicate();
    ByteBuff newBuf = allocator.allocate(capacityNeeded);

    // Copy header bytes into newBuf.
    source.position(0);
    newBuf.put(0, source, 0, headerSize);

    // set limit to exclude next block's header
    newBuf.limit(capacityNeeded);
    return newBuf;
  }
Always allocates a new buffer of the correct size. Copies header bytes from the existing
buffer. Does not change header fields. Reserve room to keep checksum bytes too.
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlock.java