def _read_stream_as_string(stream, encoding):
output = io.BytesIO()<EOL>try:<EOL><INDENT>for data in stream:<EOL><INDENT>output.write(data)<EOL><DEDENT>if encoding is None:<EOL><INDENT>encoding = '<STR_LIT:utf-8>'<EOL><DEDENT>return output.getvalue().decode(encoding)<EOL><DEDENT>finally:<EOL><INDENT>output.close()<EOL><DEDENT>raise RuntimeError('<STR_LIT>')<EOL>
Read stream as string
    Originally in azure-batch-samples.Python.Batch.common.helpers

    :param stream: input stream generator
    :param str encoding: The encoding of the file. The default is utf-8.
    :return: The file content.
    :rtype: str