0
|
1 ???using System; |
|
2 using System.IO; |
|
3 |
|
4 namespace UCIS.Util { |
|
5 public class HoldStream : Stream { |
|
6 private Stream baseStream; |
|
7 private MemoryStream buffer; |
|
8 |
|
9 public HoldStream(Stream baseStream) { |
|
10 this.baseStream = baseStream; |
|
11 this.buffer = new MemoryStream(4096); |
|
12 } |
|
13 |
|
14 public override bool CanRead { |
|
15 get { return baseStream.CanRead; } |
|
16 } |
|
17 public override bool CanSeek { |
|
18 get { return buffer.CanSeek; } |
|
19 } |
|
20 public override bool CanTimeout { |
|
21 get { return baseStream.CanTimeout; } |
|
22 } |
|
23 public override bool CanWrite { |
|
24 get { return buffer.CanWrite; } |
|
25 } |
|
26 public override void Close() { |
|
27 buffer.Close(); |
|
28 baseStream.Close(); |
|
29 } |
|
30 public override void Flush() { |
|
31 buffer.WriteTo(baseStream); |
|
32 buffer.SetLength(0); |
|
33 buffer.Seek(0, SeekOrigin.Begin); |
|
34 } |
|
35 public override void Write(byte[] buffer, int offset, int count) { |
|
36 this.buffer.Write(buffer, offset, count); |
|
37 } |
|
38 public override int Read(byte[] buffer, int offset, int count) { |
|
39 return baseStream.Read(buffer, offset, count); |
|
40 } |
|
41 public override void SetLength(long value) { |
|
42 buffer.SetLength(value); |
|
43 } |
|
44 public override long Seek(long offset, SeekOrigin origin) { |
|
45 return buffer.Seek(offset, origin); |
|
46 } |
|
47 public override long Position { |
|
48 get { return buffer.Position; } |
|
49 set { buffer.Position = value; } |
|
50 } |
|
51 public override long Length { |
|
52 get { return buffer.Length; } |
|
53 } |
|
54 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { |
|
55 return baseStream.BeginRead(buffer, offset, count, callback, state); |
|
56 } |
|
57 public override int EndRead(IAsyncResult asyncResult) { |
|
58 return baseStream.EndRead(asyncResult); |
|
59 } |
|
60 public override void WriteByte(byte value) { |
|
61 buffer.WriteByte(value); |
|
62 } |
|
63 } |
|
64 } |