Set up a StreamReader and call ReadToEnd() instead of using the GetStreamString() extension method
This eliminates some stream seeking that was never necessary and makes disposable of the StreamReader consistent with other code0.8.0.3
parent
94ad69faf2
commit
88b1fc1382
|
@ -265,13 +265,15 @@ namespace OpenSim.Framework
|
|||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
string responseStr = null;
|
||||
responseStr = responseStream.GetStreamString();
|
||||
using (StreamReader reader = new StreamReader(responseStream))
|
||||
{
|
||||
string responseStr = reader.ReadToEnd();
|
||||
// m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
|
||||
return CanonicalizeResults(responseStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException we)
|
||||
{
|
||||
errorMessage = we.Message;
|
||||
|
@ -426,15 +428,17 @@ namespace OpenSim.Framework
|
|||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
{
|
||||
string responseStr = null;
|
||||
|
||||
responseStr = responseStream.GetStreamString();
|
||||
using (StreamReader reader = new StreamReader(responseStream))
|
||||
{
|
||||
string responseStr = reader.ReadToEnd();
|
||||
OSD responseOSD = OSDParser.Deserialize(responseStr);
|
||||
|
||||
if (responseOSD.Type == OSDType.Map)
|
||||
return (OSDMap)responseOSD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException we)
|
||||
{
|
||||
errorMessage = we.Message;
|
||||
|
@ -645,38 +649,6 @@ namespace OpenSim.Framework
|
|||
return totalCopiedBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an entire stream to a string, regardless of current stream
|
||||
/// position
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to convert to a string</param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>When this method is done, the stream position will be
|
||||
/// reset to its previous position before this method was called</remarks>
|
||||
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;
|
||||
}
|
||||
|
||||
#endregion Stream
|
||||
|
||||
public class QBasedComparer : IComparer
|
||||
|
|
Loading…
Reference in New Issue