1
2
3
4
5
6 using System;
7
8 namespace System.IO
9 {
10 public enum Origin : byte
11 {
12 seekSet, seekCur, seekEnd
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* buf, long count);
24 public abstract void Write(byte x);
25 public abstract void Write(byte* buf, long count);
26 public virtual void Flush()
27 {
28 }
29 public virtual void Seek(long pos, Origin 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(destination, 16384);
40 }
41 public void CopyTo(ByteStream& destination, long 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 }