using System;

namespace DM2AE
{
	// 
	public abstract class BinaryReadThru
	{
		// 
		private System.IO.Stream m_FileIn;
		// 
		public BinaryReadThru(
			System.IO.Stream FileIn)
		{
			m_FileIn = FileIn;
		}
		// 
		public System.Byte ReadByte()
		{
			int x = m_FileIn.ReadByte();
			if (x == -1)
				throw new System.IO.EndOfStreamException("EOF Reached.");
			return (System.Byte)x;
		}
		// 
		public System.Byte[] ReadBytes(int n)
		{
			System.Byte[] x = new System.Byte[n];
			if (m_FileIn.Read(x, 0, n) != n)
				throw new System.IO.EndOfStreamException("EOF Reached.");
			return x;
		}
		// 
		public abstract System.UInt16 ReadWord();
		// 
		public abstract System.UInt32 ReadDWord();
	};
	// 
	public class BinaryReadThruLE : BinaryReadThru
	{
		// 
		public BinaryReadThruLE(
			System.IO.Stream FileIn) : base(FileIn)
		{

		}
		// 
		public override System.UInt16 ReadWord()
		{
			return (System.UInt16)(0
				|(ReadByte() << 0)
				|(ReadByte() << 8)
				);
		}
		// 
		public override System.UInt32 ReadDWord()
		{
			return (System.UInt32)(0
				|(ReadWord() << 0)
				|(ReadWord() <<16)
				);
		}
	};
	// 
	public class BinaryReadThruBE : BinaryReadThru
	{
		// 
		public BinaryReadThruBE(
			System.IO.Stream FileIn) : base(FileIn)
		{

		}
		// 
		public override System.UInt16 ReadWord()
		{
			return (System.UInt16)(0
				|(ReadByte() << 8)
				|(ReadByte() << 0)
				);
		}
		// 
		public override System.UInt32 ReadDWord()
		{
			return (System.UInt32)(0
				|(ReadWord() <<16)
				|(ReadWord() << 0)
				);
		}
	};
}
