OpenSim.Framework.WebUtil.GetStreamString C# (CSharp) Method

GetStreamString() public static method

Converts an entire stream to a string, regardless of current stream position
When this method is done, the stream position will be reset to its previous position before this method was called
public static GetStreamString ( this stream ) : string
stream this The stream to convert to a string
return string
        public static string GetStreamString(this Stream stream)
        {
            string value = null;

            if (stream != null && stream.CanRead)
            {
                long rewindPos = -1;

                if (stream.CanSeek)
                {
                    rewindPos = stream.Position;
                    stream.Seek(0, SeekOrigin.Begin);
                }

                StreamReader reader = new StreamReader(stream);
                value = reader.ReadToEnd();

                if (rewindPos >= 0)
                    stream.Seek(rewindPos, SeekOrigin.Begin);
            }

            return value;
        }