Rename the stream extension method WebUtil.CopyTo() to WebUtil.CopyStream().
.NET 4.0 added the method Stream.CopyTo(stream, bufferSize). For .NET 3.5 and before, WebUtil defined an extension method for Stream with the signature Stream.CopyTo(stream, maxBytesToCopy). The meaning of the second parameter is different in the two forms and depending on which compiler and/or runtime you use, you could get one form or the other. Crashes ensue. This change renames the WebUtil stream copy method to something that cannot be confused with the new CopyTo method defined in .NET 4.0.iar_mods^2
parent
1547fe959e
commit
e0dd38f672
|
@ -162,7 +162,7 @@ namespace OpenSim.Data.MySQL
|
||||||
using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress))
|
using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress))
|
||||||
{
|
{
|
||||||
MemoryStream outputStream = new MemoryStream();
|
MemoryStream outputStream = new MemoryStream();
|
||||||
WebUtil.CopyTo(decompressionStream, outputStream, int.MaxValue);
|
WebUtil.CopyStream(decompressionStream, outputStream, int.MaxValue);
|
||||||
// int compressedLength = asset.Data.Length;
|
// int compressedLength = asset.Data.Length;
|
||||||
asset.Data = outputStream.ToArray();
|
asset.Data = outputStream.ToArray();
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace OpenSim.Framework
|
||||||
// Copy the temporary stream to the network stream
|
// Copy the temporary stream to the network stream
|
||||||
formDataStream.Seek(0, SeekOrigin.Begin);
|
formDataStream.Seek(0, SeekOrigin.Begin);
|
||||||
using (Stream requestStream = request.GetRequestStream())
|
using (Stream requestStream = request.GetRequestStream())
|
||||||
formDataStream.CopyTo(requestStream, (int)formDataStream.Length);
|
formDataStream.CopyStream(requestStream, (int)formDataStream.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Stream Writing
|
#endregion Stream Writing
|
||||||
|
|
|
@ -510,8 +510,13 @@ namespace OpenSim.Framework
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Copying begins at the streams' current positions. The positions are
|
/// Copying begins at the streams' current positions. The positions are
|
||||||
/// NOT reset after copying is complete.
|
/// NOT reset after copying is complete.
|
||||||
|
/// NOTE!! .NET 4.0 adds the method 'Stream.CopyTo(stream, bufferSize)'.
|
||||||
|
/// This function could be replaced with that method once we move
|
||||||
|
/// totally to .NET 4.0. For versions before, this routine exists.
|
||||||
|
/// This routine used to be named 'CopyTo' but the int parameter has
|
||||||
|
/// a different meaning so this method was renamed to avoid any confusion.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static int CopyTo(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy)
|
public static int CopyStream(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
int readBytes;
|
int readBytes;
|
||||||
|
|
|
@ -477,7 +477,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
|
||||||
// Grab the asset data from the response stream
|
// Grab the asset data from the response stream
|
||||||
using (MemoryStream stream = new MemoryStream())
|
using (MemoryStream stream = new MemoryStream())
|
||||||
{
|
{
|
||||||
responseStream.CopyTo(stream, 4096);
|
responseStream.CopyStream(stream, Int32.MaxValue);
|
||||||
asset.Data = stream.ToArray();
|
asset.Data = stream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue