public static int readFully(InputStream inputStream, ByteBuffer destinationBuffer) throws IOException {
        if (!destinationBuffer.hasArray())
            throw new IllegalArgumentException("destinationBuffer must be backed by an array");
        int initialOffset = destinationBuffer.arrayOffset() + destinationBuffer.position();
        byte[] array = destinationBuffer.array();
        int length = destinationBuffer.remaining();
        int totalBytesRead = 0;
        do {
            int bytesRead = inputStream.read(array, initialOffset + totalBytesRead, length - totalBytesRead);
            if (bytesRead == -1)
                break;
            totalBytesRead += bytesRead;
        } while (length > totalBytesRead);
        destinationBuffer.position(destinationBuffer.position() + totalBytesRead);
        return totalBytesRead;
    }
Read data from the input stream to the given byte buffer until there are no bytes remaining in the buffer or the
end of the stream has been reached.

@param inputStream       Input stream to read from
@param destinationBuffer The buffer into which bytes are to be transferred (it must be backed by an array)
@return number of byte read from the input stream
@throws IOException If an I/O error occurs
clients/src/main/java/org/apache/kafka/common/utils/Utils.java