Skip to content

Commit

Permalink
Added utility method append to IOutStream<T>.Append(IInStream<T>).
Browse files Browse the repository at this point in the history
  • Loading branch information
azeno committed Feb 11, 2014
1 parent 54744cc commit 60ef70e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions common/src/core/Utils/Streams/StreamUtils.cs
Expand Up @@ -304,6 +304,30 @@ public static void AssignFrom<T>(this IOutStream<T> outStream, IInStream<T> inSt
MemoryPool<T>.PutArray(buffer);
}
}

public static void Append<T>(this IOutStream<T> outStream, IInStream<T> inStream, T[] buffer)
{
var initialOutLength = outStream.Length;
outStream.Length += inStream.Length;
using (var writer = outStream.GetWriter())
{
writer.Position = initialOutLength;
writer.Write(inStream, buffer);
}
}

public static void Append<T>(this IOutStream<T> outStream, IInStream<T> inStream)
{
var buffer = MemoryPool<T>.GetArray();
try
{
outStream.Append(inStream, buffer);
}
finally
{
MemoryPool<T>.PutArray(buffer);
}
}

// From: http://en.wikipedia.org/wiki/Power_of_two
public static bool IsPowerOfTwo(int x)
Expand Down

0 comments on commit 60ef70e

Please sign in to comment.