public static void writeTo(DataOutput out, ByteBuffer buffer, int length) throws IOException {
        if (buffer.hasArray()) {
            out.write(buffer.array(), buffer.position() + buffer.arrayOffset(), length);
        } else {
            int pos = buffer.position();
            for (int i = pos; i < length + pos; i++)
                out.writeByte(buffer.get(i));
        }
    }
Write the contents of a buffer to an output stream. The bytes are copied from the current position
in the buffer.
@param out The output to write to
@param buffer The buffer to write from
@param length The number of bytes to write
@throws IOException For any errors writing to the output
clients/src/main/java/org/apache/kafka/common/utils/Utils.java