Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StreamOnSqlBytes.cs
Go to the documentation of this file.
2using System.IO;
4
6
7internal sealed class StreamOnSqlBytes : Stream
8{
9 private SqlBytes _sb;
10
11 private long _lPosition;
12
13 public override bool CanRead
14 {
15 get
16 {
17 if (_sb != null)
18 {
19 return !_sb.IsNull;
20 }
21 return false;
22 }
23 }
24
25 public override bool CanSeek => _sb != null;
26
27 public override bool CanWrite
28 {
29 get
30 {
31 if (_sb != null)
32 {
33 if (_sb.IsNull)
34 {
35 return _sb._rgbBuf != null;
36 }
37 return true;
38 }
39 return false;
40 }
41 }
42
43 public override long Length
44 {
45 get
46 {
47 CheckIfStreamClosed("get_Length");
48 return _sb.Length;
49 }
50 }
51
52 public override long Position
53 {
54 get
55 {
56 CheckIfStreamClosed("get_Position");
57 return _lPosition;
58 }
59 set
60 {
61 CheckIfStreamClosed("set_Position");
62 if (value < 0 || value > _sb.Length)
63 {
64 throw new ArgumentOutOfRangeException("value");
65 }
67 }
68 }
69
71 {
72 _sb = sb;
73 _lPosition = 0L;
74 }
75
76 public override long Seek(long offset, SeekOrigin origin)
77 {
78 CheckIfStreamClosed("Seek");
79 long num = 0L;
80 switch (origin)
81 {
82 case SeekOrigin.Begin:
83 if (offset < 0 || offset > _sb.Length)
84 {
85 throw new ArgumentOutOfRangeException("offset");
86 }
88 break;
89 case SeekOrigin.Current:
90 num = _lPosition + offset;
91 if (num < 0 || num > _sb.Length)
92 {
93 throw new ArgumentOutOfRangeException("offset");
94 }
95 _lPosition = num;
96 break;
97 case SeekOrigin.End:
98 num = _sb.Length + offset;
99 if (num < 0 || num > _sb.Length)
100 {
101 throw new ArgumentOutOfRangeException("offset");
102 }
103 _lPosition = num;
104 break;
105 default:
106 throw ADP.InvalidSeekOrigin("offset");
107 }
108 return _lPosition;
109 }
110
111 public override int Read(byte[] buffer, int offset, int count)
112 {
113 CheckIfStreamClosed("Read");
115 int num = (int)_sb.Read(_lPosition, buffer, offset, count);
116 _lPosition += num;
117 return num;
118 }
119
120 public override void Write(byte[] buffer, int offset, int count)
121 {
122 CheckIfStreamClosed("Write");
125 _lPosition += count;
126 }
127
128 public override int ReadByte()
129 {
130 CheckIfStreamClosed("ReadByte");
131 if (_lPosition >= _sb.Length)
132 {
133 return -1;
134 }
135 int result = _sb[_lPosition];
136 _lPosition++;
137 return result;
138 }
139
140 public override void WriteByte(byte value)
141 {
142 CheckIfStreamClosed("WriteByte");
144 _lPosition++;
145 }
146
147 public override void SetLength(long value)
148 {
149 CheckIfStreamClosed("SetLength");
151 if (_lPosition > value)
152 {
154 }
155 }
156
157 public override void Flush()
158 {
159 if (_sb.FStream())
160 {
161 _sb._stream.Flush();
162 }
163 }
164
165 protected override void Dispose(bool disposing)
166 {
167 try
168 {
169 _sb = null;
170 }
171 finally
172 {
173 base.Dispose(disposing);
174 }
175 }
176
177 private bool FClosed()
178 {
179 return _sb == null;
180 }
181
182 private void CheckIfStreamClosed([CallerMemberName] string methodname = "")
183 {
184 if (FClosed())
185 {
186 throw ADP.StreamClosed(methodname);
187 }
188 }
189}
static Exception StreamClosed([CallerMemberName] string method="")
Definition ADP.cs:875
static Exception InvalidSeekOrigin(string parameterName)
Definition ADP.cs:970
void SetLength(long value)
Definition SqlBytes.cs:183
void Write(long offset, byte[] buffer, int offsetInBuffer, int count)
Definition SqlBytes.cs:254
long Read(long offset, byte[] buffer, int offsetInBuffer, int count)
Definition SqlBytes.cs:209
void CheckIfStreamClosed([CallerMemberName] string methodname="")
override long Seek(long offset, SeekOrigin origin)
override int Read(byte[] buffer, int offset, int count)
override void Dispose(bool disposing)
override void Write(byte[] buffer, int offset, int count)
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
Definition Stream.cs:1044