// // System.IO.BinaryReader // // Author: // Matt Kimball (matt@kimball.net) // Dick Porter (dick@ximian.com) // using System; using System.Text; using System.Globalization; namespace System.IO { public class BinaryReader : IDisposable { Stream m_stream; Encoding m_encoding; int m_encoding_max_byte; byte[] m_buffer; public BinaryReader(Stream input) : this(input, Encoding.UTF8) { } public BinaryReader(Stream input, Encoding encoding) { if (input == null || encoding == null) throw new ArgumentNullException(Locale.GetText ("Input or Encoding is a null reference.")); if (!input.CanRead) throw new ArgumentException(Locale.GetText ("The stream doesn't support reading.")); m_stream = input; m_encoding = encoding; m_encoding_max_byte = m_encoding.GetMaxByteCount(1); m_buffer = new byte [32]; } public virtual Stream BaseStream { get { return m_stream; } } public virtual void Close() { Dispose (true); } protected virtual void Dispose (bool disposing) { if (disposing && m_stream != null) m_stream.Close (); m_buffer = null; m_encoding = null; m_stream = null; } void IDisposable.Dispose() { Dispose (true); } protected virtual void FillBuffer(int bytes) { if(m_stream==null) { throw new IOException("Stream is invalid"); } CheckBuffer(bytes); /* Cope with partial reads */ int pos=0; while(pos