public static byte[] getNullableArray(final ByteBuffer buffer, final int size) {
        if (size > buffer.remaining()) {
            // preemptively throw this when the read is doomed to fail, so we don't have to allocate the array.
            throw new BufferUnderflowException();
        }
        final byte[] oldBytes = size == -1 ? null : new byte[size];
        if (oldBytes != null) {
            buffer.get(oldBytes);
        }
        return oldBytes;
    }
Read a byte array of the given size. Consumes the buffer: upon returning, the buffer's position
is after the array that is returned.
@param buffer The buffer to read a size-prefixed array from
@param size The number of bytes to read out of the buffer
@return The array
clients/src/main/java/org/apache/kafka/common/utils/Utils.java