annotate Util/PrebufferingStream.cs @ 49:7e4dae99f919

USBLib: fix unhandled exception in WinUSB shutdown after failure to open device
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 19 Aug 2013 16:56:50 +0200
parents 2e3f57f326b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
1 ???using System;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
2 using System.Collections.Generic;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
3 using System.Text;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
4 using System.IO;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
5 using System.Threading;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
6
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
7 namespace UCIS.Util {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
8 public class PrebufferingStream : Stream {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
9 class AsyncResult : AsyncResultBase {
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
10 public Byte[] Buffer { get; set; }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
11 public int Offset { get; set; }
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
12 public int Left { get; set; }
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
13 public int Count { get; set; }
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
14 public AsyncResult(AsyncCallback callback, Object state) : base(callback, state) { }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
15 public void SetCompleted(Boolean synchronously, int count, Exception error) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
16 this.Count = count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
17 base.SetCompleted(synchronously, error);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
18 }
37
2e3f57f326b3 Fixed some compiler warnings
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
19 public new void SetCompleted(Boolean synchronously, Exception error) {
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
20 base.SetCompleted(synchronously, error);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
21 }
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
22 public int WaitForCompletion() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
23 WaitHandle wh = null;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
24 lock (this) if (!IsCompleted) wh = AsyncWaitHandle;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
25 if (wh != null) wh.WaitOne();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
26 ThrowError();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
27 return Count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
28 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
29 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
30
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
31 Stream baseStream;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
32 Byte[] prebuffer = null;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
33 int prebufferoffset = 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
34 int prebuffercount = 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
35 int defaultbuffersize;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
36
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
37 public Stream BaseStream { get { return baseStream; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
38
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
39 public PrebufferingStream(Stream stream) : this(stream, 1024) { }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
40 public PrebufferingStream(Stream stream, int bufferSize) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
41 if (stream == null) throw new ArgumentNullException("stream");
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
42 baseStream = stream;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
43 defaultbuffersize = bufferSize;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
44 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
45
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
46 public IAsyncResult BeginPrebuffering(AsyncCallback callback, Object state) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
47 return BeginPrebuffering(1, callback, state);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
48 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
49 public IAsyncResult BeginPrebuffering(int count, AsyncCallback callback, Object state) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
50 AsyncResult ar = new AsyncResult(callback, state);
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
51 if (prebuffercount >= count) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
52 ar.SetCompleted(true, prebuffercount, null);
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
53 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
54 PrepareBuffer(count);
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
55 ar.Left = count - prebuffercount;
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
56 int off = prebufferoffset + prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
57 baseStream.BeginRead(prebuffer, off, prebuffer.Length - off, asyncPrebufferReadCallback, ar);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
58 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
59 return ar;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
60 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
61 private void asyncPrebufferReadCallback(IAsyncResult ar) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
62 AsyncResult myar = (AsyncResult)ar.AsyncState;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
63 try {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
64 int len = baseStream.EndRead(ar);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
65 if (len <= 0) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
66 myar.SetCompleted(false, prebuffercount, null);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
67 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
68 myar.Left -= len;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
69 prebuffercount += len;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
70 if (myar.Left > 0) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
71 int off = prebufferoffset + prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
72 baseStream.BeginRead(prebuffer, off, prebuffer.Length - off, asyncPrebufferReadCallback, myar);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
73 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
74 myar.SetCompleted(false, prebuffercount, null);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
75 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
76 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
77 } catch (Exception ex) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
78 myar.SetCompleted(false, prebuffercount, ex);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
79 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
80 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
81 public int EndPrebuffering(IAsyncResult ar) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
82 AsyncResult myar = (AsyncResult)ar;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
83 return myar.WaitForCompletion();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
84 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
85 public int Prebuffer() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
86 return Prebuffer(1);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
87 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
88 public int Prebuffer(int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
89 count -= prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
90 if (count <= 0) return prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
91 PrepareBuffer(prebuffercount + count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
92 while (count > 0) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
93 int off = prebufferoffset + prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
94 int len = baseStream.Read(prebuffer, off, prebuffer.Length - off);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
95 if (len <= 0) return prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
96 count -= len;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
97 prebuffercount += len;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
98 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
99 return prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
100 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
101 private void PrepareBuffer(int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
102 if (prebuffercount == 0) prebufferoffset = 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
103 if (prebuffer == null || (prebuffercount == 0 && prebuffer.Length > defaultbuffersize)) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
104 if (count < defaultbuffersize) count = defaultbuffersize;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
105 prebuffer = new Byte[count];
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
106 prebufferoffset = 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
107 } else if (prebufferoffset + count > prebuffer.Length) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
108 if (count > prebuffer.Length) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
109 Byte[] newbuffer = new Byte[prebuffercount + count];
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
110 Buffer.BlockCopy(prebuffer, prebufferoffset, newbuffer, 0, prebuffercount);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
111 prebuffer = newbuffer;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
112 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
113 Buffer.BlockCopy(prebuffer, prebufferoffset, prebuffer, 0, prebuffercount);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
114 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
115 prebufferoffset = 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
116 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
117 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
118 public Byte Peek() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
119 return Peek(0);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
120 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
121 public Byte Peek(int offset) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
122 if (Prebuffer(offset + 1) < offset + 1) throw new EndOfStreamException();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
123 return prebuffer[prebufferoffset + offset];
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
124 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
125 public void Peek(Byte[] buffer, int offset, int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
126 Peek(buffer, offset, 0, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
127 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
128 public void Peek(Byte[] buffer, int bufferoffset, int peekoffset, int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
129 if (Prebuffer(peekoffset + count) < peekoffset + count) throw new EndOfStreamException();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
130 Buffer.BlockCopy(prebuffer, prebufferoffset + peekoffset, buffer, bufferoffset, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
131 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
132 public int TryPeek() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
133 return TryPeek(0);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
134 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
135 public int TryPeek(int offset) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
136 if (prebuffercount <= offset) return -1;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
137 return prebuffer[prebufferoffset + offset];
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
138 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
139 public int TryPeek(Byte[] buffer, int offset, int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
140 return TryPeek(buffer, offset, 0, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
141 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
142 public int TryPeek(Byte[] buffer, int bufferoffset, int peekoffset, int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
143 if (prebuffercount < peekoffset + count) count = prebuffercount - peekoffset;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
144 if (count < 0) count = 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
145 if (count > 0) Buffer.BlockCopy(prebuffer, prebufferoffset + peekoffset, buffer, bufferoffset, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
146 return count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
147 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
148
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
149 public override int Read(byte[] buffer, int offset, int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
150 if (prebuffercount > 0 || count < 16) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
151 if (prebuffercount == 0) if (Prebuffer() < 1) return 0;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
152 if (count > prebuffercount) count = prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
153 Buffer.BlockCopy(prebuffer, prebufferoffset, buffer, offset, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
154 prebufferoffset += count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
155 prebuffercount -= count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
156 return count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
157 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
158 return baseStream.Read(buffer, offset, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
159 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
160 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
161
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
162 public void ReadAll(Byte[] buffer, int offset, int count) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
163 while (count > 0) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
164 int read = Read(buffer, offset, count);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
165 if (read <= 0) throw new EndOfStreamException();
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
166 offset += read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
167 count -= read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
168 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
169 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
170
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
171 public Byte[] ReadAll(int count) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
172 Byte[] buffer = new Byte[count];
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
173 ReadAll(buffer, 0, count);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
174 return buffer;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
175 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
176
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
177 public override int ReadByte() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
178 if (Prebuffer(1) < 1) return -1;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
179 int v = prebuffer[prebufferoffset];
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
180 prebufferoffset++;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
181 prebuffercount--;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
182 return v;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
183 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
184
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
185 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
186 if (prebuffercount > 0) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
187 if (count > prebuffercount) count = prebuffercount;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
188 Buffer.BlockCopy(prebuffer, prebufferoffset, buffer, offset, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
189 prebufferoffset += count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
190 prebuffercount -= count;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
191 AsyncResult ar = new AsyncResult(callback, state);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
192 ar.SetCompleted(true, count, null);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
193 return ar;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
194 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
195 return baseStream.BeginRead(buffer, offset, count, callback, state);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
196 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
197 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
198
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
199 public override int EndRead(IAsyncResult asyncResult) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
200 AsyncResult myar = asyncResult as AsyncResult;
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
201 if (myar != null) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
202 return myar.WaitForCompletion();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
203 } else {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
204 return baseStream.EndRead(asyncResult);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
205 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
206 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
207
8
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
208 public IAsyncResult BeginReadAll(byte[] buffer, int offset, int count, AsyncCallback callback, object state) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
209 AsyncResult ar = new AsyncResult(callback, state);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
210 ar.Buffer = buffer;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
211 ar.Offset = 0;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
212 ar.Left = count;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
213 ar.Count = 0;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
214 if (prebuffercount > 0) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
215 int read = Math.Min(ar.Left, prebuffercount);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
216 Buffer.BlockCopy(prebuffer, prebufferoffset, ar.Buffer, ar.Offset, read);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
217 prebufferoffset += read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
218 prebuffercount -= read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
219 ar.Offset += read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
220 ar.Left -= read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
221 ar.Count += read;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
222 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
223 if (ar.Left > 0) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
224 baseStream.BeginRead(ar.Buffer, ar.Offset, ar.Left, asyncReadAllReadCallback, ar);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
225 } else {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
226 ar.SetCompleted(true, count, null);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
227 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
228 return ar;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
229 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
230
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
231 private void asyncReadAllReadCallback(IAsyncResult ar) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
232 AsyncResult myar = (AsyncResult)ar.AsyncState;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
233 try {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
234 int len = baseStream.EndRead(ar);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
235 if (len <= 0) throw new EndOfStreamException();
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
236 myar.Offset += len;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
237 myar.Left -= len;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
238 myar.Count += len;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
239 if (myar.Left > 0) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
240 int off = prebufferoffset + prebuffercount;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
241 baseStream.BeginRead(myar.Buffer, myar.Offset, myar.Left, asyncReadAllReadCallback, ar);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
242 } else {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
243 myar.SetCompleted(false, myar.Count, null);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
244 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
245 } catch (Exception ex) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
246 myar.SetCompleted(false, ex);
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
247 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
248 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
249
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
250 public int EndReadAll(IAsyncResult asyncResult) {
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
251 AsyncResult myar = asyncResult as AsyncResult;
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
252 return myar.WaitForCompletion();
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
253 }
9525fb2d14ec Small fix and new functions in PrebufferingStream
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
254
5
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
255 public override void Close() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
256 base.Close();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
257 baseStream.Close();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
258 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
259
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
260 public override void Write(byte[] buffer, int offset, int count) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
261 baseStream.Write(buffer, offset, count);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
262 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
263
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
264 public override void WriteByte(byte value) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
265 baseStream.WriteByte(value);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
266 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
267
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
268 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
269 return baseStream.BeginWrite(buffer, offset, count, callback, state);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
270 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
271
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
272 public override void EndWrite(IAsyncResult asyncResult) {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
273 baseStream.EndWrite(asyncResult);
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
274 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
275
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
276 public override int ReadTimeout {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
277 get { return baseStream.ReadTimeout; }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
278 set { baseStream.ReadTimeout = value; }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
279 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
280
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
281 public override int WriteTimeout {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
282 get { return baseStream.WriteTimeout; }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
283 set { baseStream.WriteTimeout = value; }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
284 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
285
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
286 public override long Length { get { return prebuffercount + baseStream.Length; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
287 public override long Position {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
288 get { return baseStream.Position - prebuffercount; }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
289 set { throw new NotImplementedException(); }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
290 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
291
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
292 public override void SetLength(long value) { throw new NotImplementedException(); }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
293 public override long Seek(long offset, SeekOrigin origin) { throw new NotImplementedException(); }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
294
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
295 public override bool CanRead { get { return prebuffercount > 0 || baseStream.CanRead; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
296 public override bool CanSeek { get { return false; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
297 public override bool CanTimeout { get { return baseStream.CanTimeout; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
298 public override bool CanWrite { get { return baseStream.CanWrite; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
299
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
300 public int Buffered { get { return prebuffercount; } }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
301
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
302 public override void Flush() {
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
303 baseStream.Flush();
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
304 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
305 }
2933f7750542 Added read-buffering stream wrapper
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
306 }