public static ByteBuf readNettyByteBufFromCrcInputStream(CrcInputStream crcStream, int dataSize) throws IOException {
    ByteBuf output;
    InputStream inputStream = crcStream.getUnderlyingInputStream();
    if (inputStream instanceof NettyByteBufDataInputStream) {
      ByteBuf nettyByteBuf = ((NettyByteBufDataInputStream) inputStream).getBuffer();
      // construct a java.nio.ByteBuffer to create a ByteBufferInputStream
      int startIndex = nettyByteBuf.readerIndex();
      output = nettyByteBuf.slice(startIndex, dataSize);
      crcStream.updateCrc(output.nioBuffer());
      nettyByteBuf.readerIndex(startIndex + dataSize);
    } else {
      ByteBuffer buffer = getByteBufferFromInputStream(crcStream, dataSize);
      output = Unpooled.wrappedBuffer(buffer);
    }
    return output;
  }
Transfer {@code dataSize} bytes of data from the given crc stream to a newly create {@link ByteBuf}. The method
would also update the crc value in the crc stream.
@param crcStream The crc stream.
@param dataSize The number of bytes to transfer.
@return the newly created {@link ByteBuf} which contains the transferred data.
@throws IOException Any I/O error.
ambry-utils/src/main/java/com/github/ambry/utils/Utils.java