2 // System.Web.HttpRequestStream
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 class HttpRequestStream
: Stream
40 internal HttpRequestStream ()
44 internal HttpRequestStream (byte [] buffer
, int offset
, int length
)
46 Set (buffer
, offset
, length
);
54 internal void Set (byte [] buffer
, int offset
, int length
)
62 public override void Flush ()
66 public override void Close ()
71 public override int Read (byte [] buffer
, int offset
, int length
)
78 if (_iPos
+ length
> _iOffset
+ _iLength
) {
79 iBytes
= (int) _iOffset
+ _iLength
- _iPos
;
86 Buffer
.BlockCopy (_arrData
, _iPos
, buffer
, offset
, iBytes
);
92 public override long Seek (long offset
, SeekOrigin origin
)
95 case SeekOrigin
.Begin
:
96 if (offset
> _arrData
.Length
) {
97 throw new ArgumentException ();
101 case SeekOrigin
.Current
:
102 if (((long) _iPos
+ offset
> _arrData
.Length
) || (_iPos
+ (int) offset
< 0)) {
103 throw new ArgumentException ();
105 _iPos
+= Convert
.ToInt32 (offset
);
109 if (_arrData
.Length
- offset
< 0) {
110 throw new ArgumentException();
113 _iPos
= Convert
.ToInt32 ( _arrData
.Length
- offset
);
120 public override void SetLength (long length
)
122 throw new NotSupportedException ();
125 public override void Write (byte [] buffer
, int offset
, int length
)
127 throw new NotSupportedException ();
130 public override bool CanRead
{
134 public override bool CanSeek
{
138 public override bool CanWrite
{
139 get { return false; }
142 public byte [] Data
{
143 get { return _arrData; }
146 public int DataLength
{
147 get { return _iLength; }
150 public int DataOffset
{
151 get { return _iOffset; }
154 public override long Length
{
155 get { return (long) _arrData.Length; }
158 public override long Position
{
159 get { return (long) _iPos; }
161 set { Seek (value, SeekOrigin.Begin); }