changeset 121:9131bc46903e default tip

* Add NamedStream wrapper class to support warfoundry:#419
author IBBoard <dev@ibboard.co.uk>
date Wed, 28 Nov 2012 20:21:40 +0000
parents 780169621672
children
files IBBoard.csproj IO/NamedStream.cs
diffstat 2 files changed, 89 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.csproj	Tue Nov 06 20:51:49 2012 +0000
+++ b/IBBoard.csproj	Wed Nov 28 20:21:40 2012 +0000
@@ -158,6 +158,7 @@
     <Compile Include="IO\StreamUtil.cs" />
     <Compile Include="Collections\Collections.cs" />
     <Compile Include="Xml\XmlResourceResolver.cs" />
+    <Compile Include="IO\NamedStream.cs" />
   </ItemGroup>
   <ItemGroup>
     <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IO/NamedStream.cs	Wed Nov 28 20:21:40 2012 +0000
@@ -0,0 +1,88 @@
+//  This file (NamedStream.cs) is a part of the IBBoard project and is copyright 2012 IBBoard
+//
+//  The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using System.IO;
+
+namespace IBBoard.IO
+{
+	/// <summary>
+	/// A wrapper class to allow naming of unnamed streams (e.g. memory streams). All Stream functions
+	/// are invoked on the provided stream.
+	/// </summary>
+	public class NamedStream : Stream
+	{
+		private Stream stream;
+
+		public NamedStream(string name, Stream stream)
+		{
+			this.Name = name;
+			this.stream = stream;
+		}
+
+		public string Name { get; set; }
+
+		#region implemented abstract members of Stream
+		public override void Flush()
+		{
+			stream.Flush();
+		}
+		public override int Read(byte[] buffer, int offset, int count)
+		{
+			return stream.Read(buffer, offset, count);
+		}
+		public override long Seek(long offset, SeekOrigin origin)
+		{
+			return stream.Seek(offset, origin);
+		}
+		public override void SetLength(long value)
+		{
+			stream.SetLength(value);
+		}
+		public override void Write(byte[] buffer, int offset, int count)
+		{
+			stream.Write(buffer, offset, count);
+		}
+		public override bool CanRead
+		{
+			get
+			{
+				return stream.CanRead;
+			}
+		}
+		public override bool CanSeek
+		{
+			get
+			{
+				return stream.CanSeek;
+			}
+		}
+		public override bool CanWrite
+		{
+			get
+			{
+				return stream.CanWrite;
+			}
+		}
+		public override long Length
+		{
+			get
+			{
+				return stream.Length;
+			}
+		}
+		public override long Position
+		{
+			get
+			{
+				return stream.Position;
+			}
+			set
+			{
+				stream.Position = value;
+			}
+		}
+		#endregion
+	}
+}
+