-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (38 loc) · 1.17 KB
/
Copy pathProgram.cs
File metadata and controls
44 lines (38 loc) · 1.17 KB
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
41
42
43
44
using System;
using System.IO;
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
}