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); 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 #endregion

View File

@ -68,7 +68,10 @@ namespace OpenSim.Framework.Capabilities
/// <returns></returns> /// <returns></returns>
public static object LLSDDeserialize(byte[] b) public static object LLSDDeserialize(byte[] b)
{ {
return LLSDDeserialize(new MemoryStream(b, false)); using (MemoryStream ms = new MemoryStream(b, false))
{
return LLSDDeserialize(ms);
}
} }
/// <summary> /// <summary>
@ -78,7 +81,8 @@ namespace OpenSim.Framework.Capabilities
/// <returns></returns> /// <returns></returns>
public static object LLSDDeserialize(Stream st) public static object LLSDDeserialize(Stream st)
{ {
XmlTextReader reader = new XmlTextReader(st); using (XmlTextReader reader = new XmlTextReader(st))
{
reader.Read(); reader.Read();
SkipWS(reader); SkipWS(reader);
@ -94,6 +98,7 @@ namespace OpenSim.Framework.Capabilities
return ret; return ret;
} }
}
/// <summary> /// <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 /// 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. /// invoked by the caller in either synchronous mode or asynchronous modes.
/// </remarks> /// </remarks>
public class RestClient public class RestClient : IDisposable
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -148,6 +148,33 @@ namespace OpenSim.Framework.Communications
#endregion constructors #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> /// <summary>
/// Add a path element to the query, e.g. assets /// Add a path element to the query, e.g. assets
/// </summary> /// </summary>

View File

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

View File

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

View File

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

View File

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

View File

@ -509,6 +509,19 @@ namespace OpenSim.Framework
return sb.ToString(); 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> /// <summary>
/// Is the platform Windows? /// Is the platform Windows?
/// </summary> /// </summary>
@ -1307,46 +1320,6 @@ namespace OpenSim.Framework
return ret; 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> /// <summary>
/// Copy data from one stream to another, leaving the read position of both streams at the beginning. /// Copy data from one stream to another, leaving the read position of both streams at the beginning.
/// </summary> /// </summary>

View File

@ -176,7 +176,8 @@ namespace OpenSim.Framework
public static void LogOutgoingDetail(string context, Stream outputStream) 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; string output;
@ -262,12 +263,12 @@ namespace OpenSim.Framework
using (MemoryStream ms = new MemoryStream()) 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); comp.Write(buffer, 0, buffer.Length);
// We need to close the gzip stream before we write it anywhere // We need to close the gzip stream before we write it anywhere
// because apparently something important related to gzip compression // 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(); byte[] buf = ms.ToArray();
request.ContentLength = buf.Length; //Count bytes to send request.ContentLength = buf.Length; //Count bytes to send

View File

@ -231,7 +231,11 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
{ {
try 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) if (layerStarts != null && layerStarts.Count > 0)
{ {

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
@ -289,18 +289,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
rootElement.AppendChild(result); 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 #endregion

View File

@ -918,7 +918,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{ {
ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>(); ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
MemoryStream ms = new MemoryStream(data); using (MemoryStream ms = new MemoryStream(data))
{
if (m_displacement != Vector3.Zero || m_rotation != 0f) if (m_displacement != Vector3.Zero || m_rotation != 0f)
{ {
Vector2 rotationCenter = new Vector2(m_rotationCenter.X, m_rotationCenter.Y); Vector2 rotationCenter = new Vector2(m_rotationCenter.X, m_rotationCenter.Y);
@ -928,7 +929,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{ {
terrainModule.LoadFromStream(terrainPath, ms); terrainModule.LoadFromStream(terrainPath, ms);
} }
ms.Close(); }
m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath); 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", string terrainPath = String.Format("{0}{1}{2}.r32",
regionDir, ArchiveConstants.TERRAINS_PATH, scene.RegionInfo.RegionName); regionDir, ArchiveConstants.TERRAINS_PATH, scene.RegionInfo.RegionName);
MemoryStream ms = new MemoryStream(); using (MemoryStream ms = new MemoryStream())
{
scene.RequestModuleInterface<ITerrainModule>().SaveToStream(terrainPath, ms); scene.RequestModuleInterface<ITerrainModule>().SaveToStream(terrainPath, ms);
m_archiveWriter.WriteFile(terrainPath, ms.ToArray()); m_archiveWriter.WriteFile(terrainPath, ms.ToArray());
ms.Close(); }
m_log.InfoFormat("[ARCHIVER]: Adding scene objects to archive."); m_log.InfoFormat("[ARCHIVER]: Adding scene objects to archive.");

View File

@ -1121,9 +1121,8 @@ namespace OpenSim.Region.CoreModules.World.Estate
{ {
try try
{ {
MemoryStream terrainStream = new MemoryStream(terrainData); using (MemoryStream terrainStream = new MemoryStream(terrainData))
terr.LoadFromStream(filename, terrainStream); terr.LoadFromStream(filename, terrainStream);
terrainStream.Close();
FileInfo x = new FileInfo(filename); FileInfo x = new FileInfo(filename);
remoteClient.SendAlertMessage("Your terrain was loaded as a " + x.Extension + " file. It may take a few moments to appear."); 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); 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); string xmlstream = GetObjectXml(scene);
MemoryStream stream = ReformatXmlString(xmlstream); using (MemoryStream stream = ReformatXmlString(xmlstream))
{
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
CreateXmlFile(stream, fileName); CreateXmlFile(stream, fileName);
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
CreateCompressedXmlFile(stream, fileName); CreateCompressedXmlFile(stream, fileName);
} }
}
private static MemoryStream ReformatXmlString(string xmlstream) private static MemoryStream ReformatXmlString(string xmlstream)
{ {
@ -112,13 +113,16 @@ namespace OpenSim.Region.CoreModules.World.Serialiser
{ {
#region GZip Compressed Version #region GZip Compressed Version
FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create); using (FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create))
MemoryStream gzipMSStream = new MemoryStream(); using (MemoryStream gzipMSStream = new MemoryStream())
GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress); {
using (GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress, true))
{
xmlStream.WriteTo(gzipStream); xmlStream.WriteTo(gzipStream);
}
gzipMSStream.WriteTo(objectsFileCompressed); gzipMSStream.WriteTo(objectsFileCompressed);
objectsFileCompressed.Flush(); }
objectsFileCompressed.Close();
#endregion #endregion
} }

View File

@ -1145,7 +1145,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (myMapImageJPEG.Length == 0) if (myMapImageJPEG.Length == 0)
{ {
MemoryStream imgstream = new MemoryStream(); MemoryStream imgstream = null;
Bitmap mapTexture = new Bitmap(1,1); Bitmap mapTexture = new Bitmap(1,1);
ManagedImage managedImage; ManagedImage managedImage;
Image image = (Image)mapTexture; Image image = (Image)mapTexture;
@ -1192,12 +1192,9 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
image.Dispose(); image.Dispose();
if (imgstream != null) if (imgstream != null)
{
imgstream.Close();
imgstream.Dispose(); imgstream.Dispose();
} }
} }
}
else else
{ {
// Use cached version so we don't have to loose our mind // 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++) for (int i = 0; i < services.Length; i++)
{ {
string url = services[i].Trim(); string url = services[i].Trim();
RestClient cli = new RestClient(url); using (RestClient cli = new RestClient(url))
{
cli.AddQueryParameter("service", serviceName); cli.AddQueryParameter("service", serviceName);
cli.AddQueryParameter("host", m_hostname); cli.AddQueryParameter("host", m_hostname);
cli.AddQueryParameter("port", m_listener_port); cli.AddQueryParameter("port", m_listener_port);
@ -391,6 +392,8 @@ namespace OpenSim.Region.DataSnapshot
{ {
m_log.Warn("[DATASNAPSHOT]: Ignoring unknown exception " + e.ToString()); m_log.Warn("[DATASNAPSHOT]: Ignoring unknown exception " + e.ToString());
} }
}
byte[] response = new byte[1024]; byte[] response = new byte[1024];
// int n = 0; // int n = 0;
try try

View File

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

View File

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

View File

@ -458,9 +458,9 @@ namespace OpenSim.Region.Framework.Scenes
if (null == assetBase) if (null == assetBase)
return; return;
MemoryStream ms = new MemoryStream(assetBase.Data); using (MemoryStream ms = new MemoryStream(assetBase.Data))
StreamReader sr = new StreamReader(ms); using (StreamReader sr = new StreamReader(ms))
{
sr.ReadLine(); // Unknown (Version?) sr.ReadLine(); // Unknown (Version?)
sr.ReadLine(); // Unknown sr.ReadLine(); // Unknown
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 // If it can be parsed as a UUID, it is an asset ID
UUID uuid; UUID uuid;
if (UUID.TryParse(id, out 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) public static byte[] SerializeResult(XmlSerializer xs, object data)
{ {
MemoryStream ms = new MemoryStream(); using (MemoryStream ms = new MemoryStream())
XmlTextWriter xw = new XmlTextWriter(ms, Util.UTF8); using (XmlTextWriter xw = new XmlTextWriter(ms, Util.UTF8))
{
xw.Formatting = Formatting.Indented; xw.Formatting = Formatting.Indented;
xs.Serialize(xw, data); xs.Serialize(xw, data);
xw.Flush(); xw.Flush();
@ -208,6 +209,7 @@ namespace OpenSim.Server.Base
return ret; return ret;
} }
}
/// <summary> /// <summary>
/// Load a plugin from a dll with the given class or interface /// 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); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
byte[] GetAuthInfo(UUID principalID) byte[] GetAuthInfo(UUID principalID)
@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] SuccessResult(string token) private byte[] SuccessResult(string token)
@ -306,18 +306,7 @@ namespace OpenSim.Server.Handlers.Authentication
rootElement.AppendChild(t); rootElement.AppendChild(t);
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.GetBuffer();
} }
private byte[] ResultToBytes(Dictionary<string, object> result) private byte[] ResultToBytes(Dictionary<string, object> result)

View File

@ -247,7 +247,7 @@ namespace OpenSim.Server.Handlers.Avatar
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult() private byte[] FailureResult()
@ -269,18 +269,7 @@ namespace OpenSim.Server.Handlers.Avatar
rootElement.AppendChild(result); 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

@ -229,7 +229,7 @@ namespace OpenSim.Server.Handlers.Friends
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult() private byte[] FailureResult()
@ -261,18 +261,7 @@ namespace OpenSim.Server.Handlers.Friends
rootElement.AppendChild(message); rootElement.AppendChild(message);
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();
} }
void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags) 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); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult() private byte[] FailureResult()
@ -634,18 +634,7 @@ namespace OpenSim.Server.Handlers.Grid
rootElement.AppendChild(message); rootElement.AppendChild(message);
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 #endregion

View File

@ -279,7 +279,7 @@ namespace OpenSim.Server.Handlers.GridUser
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult() private byte[] FailureResult()
@ -301,20 +301,8 @@ namespace OpenSim.Server.Handlers.GridUser
rootElement.AppendChild(result); 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); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] SuccessResult(string value) private byte[] SuccessResult(string value)
@ -362,7 +362,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(message); rootElement.AppendChild(message);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
@ -395,7 +395,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(message); rootElement.AppendChild(message);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] BoolResult(bool value) private byte[] BoolResult(bool value)
@ -417,21 +417,9 @@ namespace OpenSim.Server.Handlers.Hypergrid
rootElement.AppendChild(result); 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 #endregion
} }
} }

View File

@ -191,18 +191,7 @@ namespace OpenSim.Server.Handlers.Asset
rootElement.AppendChild(result); 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();
} }
byte[] HandleCreateUserInventory(Dictionary<string,object> request) byte[] HandleCreateUserInventory(Dictionary<string,object> request)

View File

@ -188,7 +188,7 @@ namespace OpenSim.Server.Handlers.MapImage
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult(string msg) private byte[] FailureResult(string msg)
@ -215,18 +215,7 @@ namespace OpenSim.Server.Handlers.MapImage
rootElement.AppendChild(message); rootElement.AppendChild(message);
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();
} }
private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)

View File

@ -265,7 +265,7 @@ namespace OpenSim.Server.Handlers.Presence
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult() private byte[] FailureResult()
@ -287,18 +287,7 @@ namespace OpenSim.Server.Handlers.Presence
rootElement.AppendChild(result); 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

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

View File

@ -315,7 +315,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
rootElement.AppendChild(result); rootElement.AppendChild(result);
return DocToBytes(doc); return Util.DocToBytes(doc);
} }
private byte[] FailureResult() private byte[] FailureResult()
@ -337,18 +337,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
rootElement.AppendChild(result); 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();
} }
private byte[] ResultToBytes(Dictionary<string, object> result) private byte[] ResultToBytes(Dictionary<string, object> result)

View File

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