From 88b1fc138246866aaca91a0218dfddde1ca69252 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 27 Feb 2014 23:13:26 +0000
Subject: 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 code
---
OpenSim/Framework/WebUtil.cs | 54 +++++++++++---------------------------------
1 file changed, 13 insertions(+), 41 deletions(-)
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 6b39345..c7f1bdb 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -265,10 +265,12 @@ namespace OpenSim.Framework
{
using (Stream responseStream = response.GetResponseStream())
{
- string responseStr = null;
- responseStr = responseStream.GetStreamString();
- // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
- return CanonicalizeResults(responseStr);
+ using (StreamReader reader = new StreamReader(responseStream))
+ {
+ string responseStr = reader.ReadToEnd();
+ // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
+ return CanonicalizeResults(responseStr);
+ }
}
}
}
@@ -426,12 +428,14 @@ namespace OpenSim.Framework
{
using (Stream responseStream = response.GetResponseStream())
{
- string responseStr = null;
+ using (StreamReader reader = new StreamReader(responseStream))
+ {
+ string responseStr = reader.ReadToEnd();
+ OSD responseOSD = OSDParser.Deserialize(responseStr);
- responseStr = responseStream.GetStreamString();
- OSD responseOSD = OSDParser.Deserialize(responseStr);
- if (responseOSD.Type == OSDType.Map)
- return (OSDMap)responseOSD;
+ if (responseOSD.Type == OSDType.Map)
+ return (OSDMap)responseOSD;
+ }
}
}
}
@@ -645,38 +649,6 @@ namespace OpenSim.Framework
return totalCopiedBytes;
}
- ///
- /// Converts an entire stream to a string, regardless of current stream
- /// position
- ///
- /// The stream to convert to a string
- ///
- /// When this method is done, the stream position will be
- /// reset to its previous position before this method was called
- 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
--
cgit v1.1