-
Notifications
You must be signed in to change notification settings - Fork 18
/
Program.cs
40 lines (34 loc) · 1.01 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace Streams;
class Program
{
static void Main()
{
}
static int ReadAll(Stream s, byte[] buffer, int offset, int length)
{
if ((offset + length) > buffer.Length)
{
throw new ArgumentException("Buffer too small to hold requested data");
}
int bytesReadSoFar = 0;
while (bytesReadSoFar < length)
{
int bytes = s.Read(
buffer, offset + bytesReadSoFar, length - bytesReadSoFar);
if (bytes == 0)
{
break;
}
bytesReadSoFar += bytes;
}
return bytesReadSoFar;
}
}
// Members of Stream for illustration purposes only. These are defined by .NET so
// we don't need to define them ourselves.
#if false
public abstract int Read(byte[] buffer, int offset, int count);
public abstract void Write(byte[] buffer, int offset, int count);
public abstract long Position { get; set; }
public abstract long Seek(long offset, SeekOrigin origin);
#endif