| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- //
- // System.IO/Stream.cs
- //
- // Authors:
- // Dietmar Maurer ([email protected])
- // Miguel de Icaza ([email protected])
- //
- // (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
- //
- using System.Threading;
- namespace System.IO
- {
- [Serializable]
- 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 WaitHandle CreateWaitHandle()
- {
- return new ManualResetEvent (false);
- }
-
- 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);
- }
- delegate int ReadDelegate (byte [] buffer, int offset, int count);
- [MonoTODO]
- public virtual IAsyncResult
- BeginRead (byte [] buffer, int offset, int count, AsyncCallback cback, object state)
- {
- if (!CanRead)
- throw new NotSupportedException ("This stream does not support reading");
- return null;
- }
- [MonoTODO]
- public virtual IAsyncResult
- BeginWrite (byte [] buffer, int offset, int count, AsyncCallback cback, object state)
- {
- return null;
- }
-
- [MonoTODO]
- public virtual int EndRead (IAsyncResult async_result)
- {
- if (async_result == null)
- throw new ArgumentNullException ("async_result");
- return 0;
- }
- [MonoTODO]
- public virtual int EndWrite (IAsyncResult async_result)
- {
- if (async_result == null)
- throw new ArgumentNullException ("async_result");
- return 0;
- }
- }
- class NullStream : Stream
- {
- 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 0;
- }
- }
- public override long Position
- {
- get {
- return 0;
- }
- set {
- }
- }
- public override void Flush ()
- {
- }
- public override int Read (byte[] buffer,
- int offset,
- int count)
- {
- return 0;
- }
- public override int ReadByte ()
- {
- return 0;
- }
- public override long Seek (long offset,
- SeekOrigin origin)
- {
- return 0;
- }
- public override void SetLength (long value)
- {
- }
- public override void Write (byte[] buffer,
- int offset,
- int count)
- {
- }
- public override void WriteByte (byte value)
- {
- }
- }
- }
|