1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System;
 7 
 8 namespace System.IO
 9 {
10     public enum Origin : byte
11     {
12         seekSetseekCurseekEnd
13     }
14 
15     public abstract class ByteStream
16     {
17         public virtual default ~ByteStream();
18         suppress ByteStream(const ByteStream&);
19         suppress void operator=(const ByteStream&);
20         public default nothrow ByteStream(ByteStream&&);
21         public default nothrow void operator=(ByteStream&&);
22         public abstract int ReadByte();
23         public abstract long Read(byte* buflong count);
24         public abstract void Write(byte x);
25         public abstract void Write(byte* buflong count);
26         public virtual void Flush()
27         {
28         }
29         public virtual void Seek(long posOrigin origin)
30         {
31             throw FileSystemException("this stream does not support seek");
32         }
33         public virtual long Tell()
34         {
35             throw FileSystemException("this stream does not support tell");
36         }
37         public void CopyTo(ByteStream& destination)
38         {
39             this->CopyTo(destination16384);
40         }
41         public void CopyTo(ByteStream& destinationlong bufferSize)
42         {
43             if (bufferSize <= 0)
44             {
45                 ThrowInvalidParameterException();
46             }
47             IOBuffer buffer(bufferSize);
48             long bytesRead = Read(cast<byte*>(buffer.Mem())bufferSize);
49             while (bytesRead > 0)
50             {
51                 destination.Write(cast<byte*>(buffer.Mem())bytesRead);
52                 bytesRead = Read(cast<byte*>(buffer.Mem())bufferSize);
53             }
54         }
55     }
56 }