public static ByteBuffer readByteBufferFromCrcInputStream(CrcInputStream crcStream, int dataSize) throws IOException {
    ByteBuffer output;
    InputStream inputStream = crcStream.getUnderlyingInputStream();
    if (inputStream instanceof NettyByteBufDataInputStream) {
      // getBuffer() doesn't increase the reference count on this ByteBuf.
      ByteBuf nettyByteBuf = ((NettyByteBufDataInputStream) inputStream).getBuffer();
      // construct a java.nio.ByteBuffer to create a ByteBufferInputStream
      int startIndex = nettyByteBuf.readerIndex();
      output = nettyByteBuf.nioBuffer(startIndex, dataSize);
      crcStream.updateCrc(output.duplicate());
      nettyByteBuf.readerIndex(startIndex + dataSize);
    } else {
      output = getByteBufferFromInputStream(crcStream, dataSize);
    }
    return output;
  }
Transfer {@code dataSize} bytes of data from the given crc stream to a newly create {@link ByteBuffer}. 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 ByteBuffer} which contains the transferred data.
@throws IOException Any I/O error.
ambry-utils/src/main/java/com/github/ambry/utils/Utils.java