changeset 121:9131bc46903e 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 diff
     1.1 --- a/IBBoard.csproj	Tue Nov 06 20:51:49 2012 +0000
     1.2 +++ b/IBBoard.csproj	Wed Nov 28 20:21:40 2012 +0000
     1.3 @@ -158,6 +158,7 @@
     1.4      <Compile Include="IO\StreamUtil.cs" />
     1.5      <Compile Include="Collections\Collections.cs" />
     1.6      <Compile Include="Xml\XmlResourceResolver.cs" />
     1.7 +    <Compile Include="IO\NamedStream.cs" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/IO/NamedStream.cs	Wed Nov 28 20:21:40 2012 +0000
     2.3 @@ -0,0 +1,88 @@
     2.4 +//  This file (NamedStream.cs) is a part of the IBBoard project and is copyright 2012 IBBoard
     2.5 +//
     2.6 +//  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.
     2.7 +using System;
     2.8 +using System.IO;
     2.9 +
    2.10 +namespace IBBoard.IO
    2.11 +{
    2.12 +	/// <summary>
    2.13 +	/// A wrapper class to allow naming of unnamed streams (e.g. memory streams). All Stream functions
    2.14 +	/// are invoked on the provided stream.
    2.15 +	/// </summary>
    2.16 +	public class NamedStream : Stream
    2.17 +	{
    2.18 +		private Stream stream;
    2.19 +
    2.20 +		public NamedStream(string name, Stream stream)
    2.21 +		{
    2.22 +			this.Name = name;
    2.23 +			this.stream = stream;
    2.24 +		}
    2.25 +
    2.26 +		public string Name { get; set; }
    2.27 +
    2.28 +		#region implemented abstract members of Stream
    2.29 +		public override void Flush()
    2.30 +		{
    2.31 +			stream.Flush();
    2.32 +		}
    2.33 +		public override int Read(byte[] buffer, int offset, int count)
    2.34 +		{
    2.35 +			return stream.Read(buffer, offset, count);
    2.36 +		}
    2.37 +		public override long Seek(long offset, SeekOrigin origin)
    2.38 +		{
    2.39 +			return stream.Seek(offset, origin);
    2.40 +		}
    2.41 +		public override void SetLength(long value)
    2.42 +		{
    2.43 +			stream.SetLength(value);
    2.44 +		}
    2.45 +		public override void Write(byte[] buffer, int offset, int count)
    2.46 +		{
    2.47 +			stream.Write(buffer, offset, count);
    2.48 +		}
    2.49 +		public override bool CanRead
    2.50 +		{
    2.51 +			get
    2.52 +			{
    2.53 +				return stream.CanRead;
    2.54 +			}
    2.55 +		}
    2.56 +		public override bool CanSeek
    2.57 +		{
    2.58 +			get
    2.59 +			{
    2.60 +				return stream.CanSeek;
    2.61 +			}
    2.62 +		}
    2.63 +		public override bool CanWrite
    2.64 +		{
    2.65 +			get
    2.66 +			{
    2.67 +				return stream.CanWrite;
    2.68 +			}
    2.69 +		}
    2.70 +		public override long Length
    2.71 +		{
    2.72 +			get
    2.73 +			{
    2.74 +				return stream.Length;
    2.75 +			}
    2.76 +		}
    2.77 +		public override long Position
    2.78 +		{
    2.79 +			get
    2.80 +			{
    2.81 +				return stream.Position;
    2.82 +			}
    2.83 +			set
    2.84 +			{
    2.85 +				stream.Position = value;
    2.86 +			}
    2.87 +		}
    2.88 +		#endregion
    2.89 +	}
    2.90 +}
    2.91 +