| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- //
- // System.IO/Stream.cs
- //
- // Author:
- // Dietmar Maurer ([email protected])
- //
- // (C) 2001 Ximian, Inc. http://www.ximian.com
- //
- namespace System.IO
- {
- public abstract class Stream : MarshalByRefObject, IDisposable
- {
- // public static readonly Stream Null;
- static Stream ()
- {
- //Null = new NullStream ();
- }
- protected Stream ()
- {
- }
- public abstract bool CanRead
- {
- get;
- }
- public abstract bool CanSeek
- {
- get;
- }
- public abstract bool CanWrite
- {
- get;
- }
- public abstract long Length
- {
- get;
- }
- public abstract long Position
- {
- get;
- set;
- }
- public virtual void Close ()
- {
- Flush ();
- }
- public virtual void Dispose ()
- {
- }
-
- protected virtual void Dispose (bool disposing)
- {
- }
- ~Stream ()
- {
- }
- public abstract void Flush ();
- public abstract int Read (byte[] buffer,
- int offset,
- int count);
- public virtual int ReadByte ()
- {
- byte[] buffer = new byte [1];
- if (Read (buffer, 0, 1) == 1)
- return buffer [0];
-
- return -1;
- }
- public abstract long Seek (long offset,
- SeekOrigin origin);
- public abstract void SetLength (long value);
- public abstract void Write (byte[] buffer,
- int offset,
- int count);
- public virtual void WriteByte (byte value)
- {
- byte[] buffer = new byte [1];
- buffer [0] = value;
- Write (buffer, 0, 1);
- }
- }
- class NullStream : Stream
- {
- private long position = 0;
- private long length = System.Int64.MaxValue;
- public override bool CanRead
- {
- get {
- return true;
- }
- }
- public override bool CanSeek
- {
- get {
- return true;
- }
- }
- public override bool CanWrite
- {
- get {
- return true;
- }
- }
- public override long Length
- {
- get {
- return length;
- }
- }
- public override long Position
- {
- get {
- return position;
- }
- set {
- position = value;
- }
- }
- public override void Flush ()
- {
- }
- public override int Read (byte[] buffer,
- int offset,
- int count)
- {
- int max = offset + count;
-
- for (int i = offset; i < max; i++)
- buffer [i] = 0;
- return count;
- }
- public override int ReadByte ()
- {
- return 0;
- }
- public override long Seek (long offset,
- SeekOrigin origin)
- {
- switch (origin) {
- case SeekOrigin.Begin:
- position = offset;
- break;
- case SeekOrigin.Current:
- position = position + offset;
- break;
- case SeekOrigin.End:
- position = Length - offset;
- break;
- }
- return position;
- }
- public override void SetLength (long value)
- {
- length = value;
- }
- public override void Write (byte[] buffer,
- int offset,
- int count)
- {
- }
- public override void WriteByte (byte value)
- {
- }
- }
- }
|