Close streams immediately when we finish using them

bullet-2.82
Oren Hurvitz 2014-06-01 17:39:11 +03:00
parent b81187db5a
commit 99ac770abb
34 changed files with 426 additions and 485 deletions

View File

@ -215,18 +215,7 @@ namespace OpenSim.OfflineIM
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
#endregion

View File

@ -68,7 +68,10 @@ namespace OpenSim.Framework.Capabilities
/// <returns></returns>
public static object LLSDDeserialize(byte[] b)
{
return LLSDDeserialize(new MemoryStream(b, false));
using (MemoryStream ms = new MemoryStream(b, false))
{
return LLSDDeserialize(ms);
}
}
/// <summary>
@ -78,7 +81,8 @@ namespace OpenSim.Framework.Capabilities
/// <returns></returns>
public static object LLSDDeserialize(Stream st)
{
XmlTextReader reader = new XmlTextReader(st);
using (XmlTextReader reader = new XmlTextReader(st))
{
reader.Read();
SkipWS(reader);
@ -94,6 +98,7 @@ namespace OpenSim.Framework.Capabilities
return ret;
}
}
/// <summary>
///

View File

@ -56,7 +56,7 @@ namespace OpenSim.Framework.Communications
/// other threads to execute, while it waits for a response from the web-service. RestClient itself can be
/// invoked by the caller in either synchronous mode or asynchronous modes.
/// </remarks>
public class RestClient
public class RestClient : IDisposable
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -148,6 +148,33 @@ namespace OpenSim.Framework.Communications
#endregion constructors
#region Dispose
private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
_resource.Dispose();
}
disposed = true;
}
#endregion Dispose
/// <summary>
/// Add a path element to the query, e.g. assets
/// </summary>

View File

@ -832,9 +832,14 @@ namespace OpenSim.Framework.Servers.HttpServer
return; // never log these; they're just binary data
Stream inputStream = Util.Copy(request.InputStream);
Stream innerStream = null;
try
{
if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress);
{
innerStream = inputStream;
inputStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
}
using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))
{
@ -856,6 +861,13 @@ namespace OpenSim.Framework.Servers.HttpServer
m_log.DebugFormat("[LOGHTTP] {0}", Util.BinaryToASCII(output));
}
}
finally
{
if (innerStream != null)
innerStream.Dispose();
inputStream.Dispose();
}
}
private readonly string HANDLER_SEPARATORS = "/?&#-";
@ -981,19 +993,33 @@ namespace OpenSim.Framework.Servers.HttpServer
/// <param name="response"></param>
private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
{
String requestBody;
Stream requestStream = request.InputStream;
Stream innerStream = null;
try
{
if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
requestStream = new GZipStream(requestStream, System.IO.Compression.CompressionMode.Decompress);
{
innerStream = requestStream;
requestStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
}
Encoding encoding = Encoding.UTF8;
StreamReader reader = new StreamReader(requestStream, encoding);
using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
{
requestBody = reader.ReadToEnd();
}
}
finally
{
if (innerStream != null)
innerStream.Dispose();
requestStream.Dispose();
}
string requestBody = reader.ReadToEnd();
reader.Close();
requestStream.Close();
//m_log.Debug(requestBody);
requestBody = requestBody.Replace("<base64></base64>", "");
string responseString = String.Empty;
XmlRpcRequest xmlRprcRequest = null;
@ -1089,7 +1115,6 @@ namespace OpenSim.Framework.Servers.HttpServer
response.ContentType = "text/xml";
using (MemoryStream outs = new MemoryStream())
{
using (XmlTextWriter writer = new XmlTextWriter(outs, Encoding.UTF8))
{
writer.Formatting = Formatting.None;
@ -1103,7 +1128,6 @@ namespace OpenSim.Framework.Servers.HttpServer
}
}
}
}
else
{
//HandleLLSDRequests(request, response);

View File

@ -52,8 +52,8 @@ namespace OpenSim.Framework.Servers.HttpServer
request.Method = verb;
request.ContentType = "text/xml";
MemoryStream buffer = new MemoryStream();
using (MemoryStream buffer = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
@ -67,8 +67,10 @@ namespace OpenSim.Framework.Servers.HttpServer
int length = (int)buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
using (Stream requestStream = request.GetRequestStream())
requestStream.Write(buffer.ToArray(), 0, length);
}
// IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
request.BeginGetResponse(AsyncCallback, request);
}

View File

@ -60,8 +60,8 @@ namespace OpenSim.Framework.Servers.HttpServer
request.ContentType = "text/xml";
request.Timeout = 10000;
MemoryStream buffer = new MemoryStream();
using (MemoryStream buffer = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
@ -75,9 +75,10 @@ namespace OpenSim.Framework.Servers.HttpServer
int length = (int)buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
using (Stream requestStream = request.GetRequestStream())
requestStream.Write(buffer.ToArray(), 0, length);
requestStream.Close();
}
// IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
request.BeginGetResponse(AsyncCallback, request);
}

View File

@ -77,8 +77,8 @@ namespace OpenSim.Framework.Servers.HttpServer
request.ContentType = "text/xml";
request.Timeout = 20000;
MemoryStream buffer = new MemoryStream();
using (MemoryStream buffer = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
@ -92,10 +92,9 @@ namespace OpenSim.Framework.Servers.HttpServer
int length = (int)buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
using (Stream requestStream = request.GetRequestStream())
requestStream.Write(buffer.ToArray(), 0, length);
buffer.Close();
requestStream.Close();
}
TResponse deserial = default(TResponse);
using (WebResponse resp = request.GetResponse())
@ -133,8 +132,8 @@ namespace OpenSim.Framework.Servers.HttpServer
request.ContentType = "text/xml";
request.Timeout = 10000;
MemoryStream buffer = new MemoryStream();
using (MemoryStream buffer = new MemoryStream())
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
@ -144,14 +143,14 @@ namespace OpenSim.Framework.Servers.HttpServer
serializer.Serialize(writer, sobj);
writer.Flush();
}
buffer.Close();
int length = (int)buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
using (Stream requestStream = request.GetRequestStream())
requestStream.Write(buffer.ToArray(), 0, length);
requestStream.Close();
}
// IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
request.BeginGetResponse(AsyncCallback, request);
}

View File

@ -509,6 +509,19 @@ namespace OpenSim.Framework
return sb.ToString();
}
public static byte[] DocToBytes(XmlDocument doc)
{
using (MemoryStream ms = new MemoryStream())
using (XmlTextWriter xw = new XmlTextWriter(ms, null))
{
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
}
/// <summary>
/// Is the platform Windows?
/// </summary>
@ -1307,46 +1320,6 @@ namespace OpenSim.Framework
return ret;
}
public static string Compress(string text)
{
byte[] buffer = Util.UTF8.GetBytes(text);
MemoryStream memory = new MemoryStream();
using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
{
compressor.Write(buffer, 0, buffer.Length);
}
memory.Position = 0;
byte[] compressed = new byte[memory.Length];
memory.Read(compressed, 0, compressed.Length);
byte[] compressedBuffer = new byte[compressed.Length + 4];
Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
return Convert.ToBase64String(compressedBuffer);
}
public static string Decompress(string compressedText)
{
byte[] compressedBuffer = Convert.FromBase64String(compressedText);
using (MemoryStream memory = new MemoryStream())
{
int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
byte[] buffer = new byte[msgLength];
memory.Position = 0;
using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
{
decompressor.Read(buffer, 0, buffer.Length);
}
return Util.UTF8.GetString(buffer);
}
}
/// <summary>
/// Copy data from one stream to another, leaving the read position of both streams at the beginning.
/// </summary>

View File

@ -176,7 +176,8 @@ namespace OpenSim.Framework
public static void LogOutgoingDetail(string context, Stream outputStream)
{
using (StreamReader reader = new StreamReader(Util.Copy(outputStream), Encoding.UTF8))
using (Stream stream = Util.Copy(outputStream))
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
string output;
@ -262,12 +263,12 @@ namespace OpenSim.Framework
using (MemoryStream ms = new MemoryStream())
{
using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress))
using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress, true))
{
comp.Write(buffer, 0, buffer.Length);
// We need to close the gzip stream before we write it anywhere
// because apparently something important related to gzip compression
// gets written on the strteam upon Dispose()
// gets written on the stream upon Dispose()
}
byte[] buf = ms.ToArray();
request.ContentLength = buf.Length; //Count bytes to send

View File

@ -231,7 +231,11 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
{
try
{
List<int> layerStarts = CSJ2K.J2kImage.GetLayerBoundaries(new MemoryStream(j2kData));
List<int> layerStarts;
using (MemoryStream ms = new MemoryStream(j2kData))
{
layerStarts = CSJ2K.J2kImage.GetLayerBoundaries(ms);
}
if (layerStarts != null && layerStarts.Count > 0)
{

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
@ -289,18 +289,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
#endregion

View File

@ -918,7 +918,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
MemoryStream ms = new MemoryStream(data);
using (MemoryStream ms = new MemoryStream(data))
{
if (m_displacement != Vector3.Zero || m_rotation != 0f)
{
Vector2 rotationCenter = new Vector2(m_rotationCenter.X, m_rotationCenter.Y);
@ -928,7 +929,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
terrainModule.LoadFromStream(terrainPath, ms);
}
ms.Close();
}
m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath);

View File

@ -569,10 +569,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver
string terrainPath = String.Format("{0}{1}{2}.r32",
regionDir, ArchiveConstants.TERRAINS_PATH, scene.RegionInfo.RegionName);
MemoryStream ms = new MemoryStream();
using (MemoryStream ms = new MemoryStream())
{
scene.RequestModuleInterface<ITerrainModule>().SaveToStream(terrainPath, ms);
m_archiveWriter.WriteFile(terrainPath, ms.ToArray());
ms.Close();
}
m_log.InfoFormat("[ARCHIVER]: Adding scene objects to archive.");

View File

@ -1121,9 +1121,8 @@ namespace OpenSim.Region.CoreModules.World.Estate
{
try
{
MemoryStream terrainStream = new MemoryStream(terrainData);
using (MemoryStream terrainStream = new MemoryStream(terrainData))
terr.LoadFromStream(filename, terrainStream);
terrainStream.Close();
FileInfo x = new FileInfo(filename);
remoteClient.SendAlertMessage("Your terrain was loaded as a " + x.Extension + " file. It may take a few moments to appear.");

View File

@ -281,18 +281,8 @@ namespace OpenSim.Region.CoreModules.World.Estate
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
}
}

View File

@ -54,14 +54,15 @@ namespace OpenSim.Region.CoreModules.World.Serialiser
{
string xmlstream = GetObjectXml(scene);
MemoryStream stream = ReformatXmlString(xmlstream);
using (MemoryStream stream = ReformatXmlString(xmlstream))
{
stream.Seek(0, SeekOrigin.Begin);
CreateXmlFile(stream, fileName);
stream.Seek(0, SeekOrigin.Begin);
CreateCompressedXmlFile(stream, fileName);
}
}
private static MemoryStream ReformatXmlString(string xmlstream)
{
@ -112,13 +113,16 @@ namespace OpenSim.Region.CoreModules.World.Serialiser
{
#region GZip Compressed Version
FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create);
MemoryStream gzipMSStream = new MemoryStream();
GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
using (FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create))
using (MemoryStream gzipMSStream = new MemoryStream())
{
using (GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress, true))
{
xmlStream.WriteTo(gzipStream);
}
gzipMSStream.WriteTo(objectsFileCompressed);
objectsFileCompressed.Flush();
objectsFileCompressed.Close();
}
#endregion
}

View File

@ -1145,7 +1145,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (myMapImageJPEG.Length == 0)
{
MemoryStream imgstream = new MemoryStream();
MemoryStream imgstream = null;
Bitmap mapTexture = new Bitmap(1,1);
ManagedImage managedImage;
Image image = (Image)mapTexture;
@ -1192,12 +1192,9 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
image.Dispose();
if (imgstream != null)
{
imgstream.Close();
imgstream.Dispose();
}
}
}
else
{
// Use cached version so we don't have to loose our mind

View File

@ -373,7 +373,8 @@ namespace OpenSim.Region.DataSnapshot
for (int i = 0; i < services.Length; i++)
{
string url = services[i].Trim();
RestClient cli = new RestClient(url);
using (RestClient cli = new RestClient(url))
{
cli.AddQueryParameter("service", serviceName);
cli.AddQueryParameter("host", m_hostname);
cli.AddQueryParameter("port", m_listener_port);
@ -391,6 +392,8 @@ namespace OpenSim.Region.DataSnapshot
{
m_log.Warn("[DATASNAPSHOT]: Ignoring unknown exception " + e.ToString());
}
}
byte[] response = new byte[1024];
// int n = 0;
try

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
@ -113,9 +113,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation
public byte[] ToBytes()
{
byte[] outputbytes = new byte[0];
byte[] outputbytes;
BinaryWriter iostream = new BinaryWriter(new MemoryStream());
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter iostream = new BinaryWriter(ms))
{
iostream.Write(BinBVHUtil.ES(Utils.UInt16ToBytes(unknown0)));
iostream.Write(BinBVHUtil.ES(Utils.UInt16ToBytes(unknown1)));
iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(Priority)));
@ -134,10 +136,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation
Joints[i].WriteBytesToStream(iostream, InPoint, OutPoint);
}
iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(0)));
MemoryStream ms = (MemoryStream)iostream.BaseStream;
outputbytes = ms.ToArray();
ms.Close();
iostream.Close();
using (MemoryStream ms2 = (MemoryStream)iostream.BaseStream)
outputbytes = ms2.ToArray();
}
return outputbytes;
}

View File

@ -308,10 +308,11 @@ namespace OpenSim.Region.Framework.Scenes
try
{
MemoryStream ms = new MemoryStream(data);
using (MemoryStream ms = new MemoryStream(data))
{
BinaryFormatter fmt = new BinaryFormatter();
newMotion = (KeyframeMotion)fmt.Deserialize(ms);
}
newMotion.m_group = grp;
@ -764,13 +765,15 @@ namespace OpenSim.Region.Framework.Scenes
public Byte[] Serialize()
{
StopTimer();
MemoryStream ms = new MemoryStream();
BinaryFormatter fmt = new BinaryFormatter();
SceneObjectGroup tmp = m_group;
m_group = null;
if (!m_selected && tmp != null)
m_serializedPosition = tmp.AbsolutePosition;
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter fmt = new BinaryFormatter();
fmt.Serialize(ms, this);
m_group = tmp;
if (m_running && !m_waitingCrossing)
@ -778,6 +781,7 @@ namespace OpenSim.Region.Framework.Scenes
return ms.ToArray();
}
}
public void StartCrossingCheck()
{

View File

@ -458,9 +458,9 @@ namespace OpenSim.Region.Framework.Scenes
if (null == assetBase)
return;
MemoryStream ms = new MemoryStream(assetBase.Data);
StreamReader sr = new StreamReader(ms);
using (MemoryStream ms = new MemoryStream(assetBase.Data))
using (StreamReader sr = new StreamReader(ms))
{
sr.ReadLine(); // Unknown (Version?)
sr.ReadLine(); // Unknown
sr.ReadLine(); // Unknown
@ -486,7 +486,8 @@ namespace OpenSim.Region.Framework.Scenes
// If it can be parsed as a UUID, it is an asset ID
UUID uuid;
if (UUID.TryParse(id, out uuid))
assetUuids[uuid] = (sbyte)AssetType.Animation;
assetUuids[uuid] = (sbyte)AssetType.Animation; // the asset is either an Animation or a Sound, but this distinction isn't important
}
}
}

View File

@ -196,8 +196,9 @@ namespace OpenSim.Server.Base
public static byte[] SerializeResult(XmlSerializer xs, object data)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, Util.UTF8);
using (MemoryStream ms = new MemoryStream())
using (XmlTextWriter xw = new XmlTextWriter(ms, Util.UTF8))
{
xw.Formatting = Formatting.Indented;
xs.Serialize(xw, data);
xw.Flush();
@ -208,6 +209,7 @@ namespace OpenSim.Server.Base
return ret;
}
}
/// <summary>
/// Load a plugin from a dll with the given class or interface

View File

@ -209,7 +209,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
byte[] GetAuthInfo(UUID principalID)
@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] SuccessResult(string token)
@ -306,18 +306,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(t);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.GetBuffer();
return Util.DocToBytes(doc);
}
private byte[] ResultToBytes(Dictionary<string, object> result)

View File

@ -247,7 +247,7 @@ namespace OpenSim.Server.Handlers.Avatar
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@ -269,18 +269,7 @@ namespace OpenSim.Server.Handlers.Avatar
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
}

View File

@ -229,7 +229,7 @@ namespace OpenSim.Server.Handlers.Friends
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@ -261,18 +261,7 @@ namespace OpenSim.Server.Handlers.Friends
rootElement.AppendChild(message);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags)

View File

@ -602,7 +602,7 @@ namespace OpenSim.Server.Handlers.Grid
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@ -634,18 +634,7 @@ namespace OpenSim.Server.Handlers.Grid
rootElement.AppendChild(message);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
#endregion

View File

@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.GridUser
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@ -301,20 +301,8 @@ namespace OpenSim.Server.Handlers.GridUser
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
}
}

View File

@ -335,7 +335,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] SuccessResult(string value)
@ -362,7 +362,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(message);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
@ -395,7 +395,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(message);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] BoolResult(bool value)
@ -417,21 +417,9 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
}
#endregion
}
}

View File

@ -191,18 +191,7 @@ namespace OpenSim.Server.Handlers.Asset
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
byte[] HandleCreateUserInventory(Dictionary<string,object> request)

View File

@ -188,7 +188,7 @@ namespace OpenSim.Server.Handlers.MapImage
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult(string msg)
@ -215,18 +215,7 @@ namespace OpenSim.Server.Handlers.MapImage
rootElement.AppendChild(message);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)

View File

@ -265,7 +265,7 @@ namespace OpenSim.Server.Handlers.Presence
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@ -287,18 +287,7 @@ namespace OpenSim.Server.Handlers.Presence
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
}

View File

@ -250,14 +250,30 @@ namespace OpenSim.Server.Handlers.Simulation
return encoding.GetBytes("false");
}
string requestBody;
Stream inputStream = request;
Stream innerStream = null;
try
{
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
{
innerStream = inputStream;
inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
}
StreamReader reader = new StreamReader(inputStream, encoding);
using (StreamReader reader = new StreamReader(inputStream, encoding))
{
requestBody = reader.ReadToEnd();
}
}
finally
{
if (innerStream != null)
innerStream.Dispose();
inputStream.Dispose();
}
string requestBody = reader.ReadToEnd();
reader.Close();
keysvals.Add("body", requestBody);
Hashtable responsedata = new Hashtable();
@ -461,15 +477,31 @@ namespace OpenSim.Server.Handlers.Simulation
keysvals.Add("headers", headervals);
keysvals.Add("querystringkeys", querystringkeys);
Stream inputStream = request;
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
inputStream = new GZipStream(inputStream, CompressionMode.Decompress);
String requestBody;
Encoding encoding = Encoding.UTF8;
StreamReader reader = new StreamReader(inputStream, encoding);
string requestBody = reader.ReadToEnd();
reader.Close();
Stream inputStream = request;
Stream innerStream = null;
try
{
if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
{
innerStream = inputStream;
inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
}
using (StreamReader reader = new StreamReader(inputStream, encoding))
{
requestBody = reader.ReadToEnd();
}
}
finally
{
if (innerStream != null)
innerStream.Dispose();
inputStream.Dispose();
}
keysvals.Add("body", requestBody);
httpResponse.StatusCode = 200;

View File

@ -315,7 +315,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
rootElement.AppendChild(result);
return DocToBytes(doc);
return Util.DocToBytes(doc);
}
private byte[] FailureResult()
@ -337,18 +337,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
rootElement.AppendChild(result);
return DocToBytes(doc);
}
private byte[] DocToBytes(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlTextWriter xw = new XmlTextWriter(ms, null);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
xw.Flush();
return ms.ToArray();
return Util.DocToBytes(doc);
}
private byte[] ResultToBytes(Dictionary<string, object> result)

View File

@ -171,7 +171,8 @@ namespace OpenSim.Services.Connectors
return fullAsset.Data;
}
RestClient rc = new RestClient(m_ServerURI);
using (RestClient rc = new RestClient(m_ServerURI))
{
rc.AddResourcePath("assets");
rc.AddResourcePath(id);
rc.AddResourcePath("data");
@ -193,6 +194,7 @@ namespace OpenSim.Services.Connectors
return null;
}
}
public bool Get(string id, Object sender, AssetRetrieved handler)
{