using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace Harlinn.Common.IO
{
public class BinaryOutputStream : IDisposable
{
System.IO.Stream stream;
int version;
BinaryWriter writer;
public BinaryOutputStream(System.IO.Stream stream, int version)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
writer = new BinaryWriter(stream);
this.version = version;
writer.Write(version);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if(writer != null)
{
writer.Dispose();
writer = null;
}
if (stream != null)
{
stream.Dispose();
stream = null;
}
}
}
~BinaryOutputStream()
{
Dispose(false);
}
public bool CanSeek
{
get
{
return stream.CanSeek;
}
}
[ComVisible(false)]
public bool CanTimeout
{
get
{
return stream.CanTimeout;
}
}
public bool CanWrite
{
get
{
return stream.CanWrite;
}
}
public long Length
{
get
{
return stream.Length;
}
}
public long Position
{
get
{
return stream.Position;
}
}
[ComVisible(false)]
public int WriteTimeout
{
get
{
return stream.WriteTimeout;
}
set
{
stream.WriteTimeout = value;
}
}
public IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return stream.BeginWrite(buffer, offset, count, callback, state);
}
public void Close()
{
stream.Close();
}
public void EndWrite(IAsyncResult asyncResult)
{
stream.EndWrite(asyncResult);
}
public void Flush()
{
stream.Flush();
}
public long Seek(long offset, System.IO.SeekOrigin origin)
{
return stream.Seek(offset, origin);
}
public void SetLength(long value)
{
stream.SetLength(value);
}
public void Write(byte[] buffer, int offset, int count)
{
stream.Write(buffer, offset, count);
}
public void WriteByte(byte value)
{
stream.WriteByte(value);
}
}
}