(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web / HttpRequestStream.cs
blob419ad9b2b406c38c18008ae1284edbd6f340dd47
1 //
2 // System.Web.HttpRequestStream
3 //
4 // Author:
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 //
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
28 using System;
29 using System.IO;
31 namespace System.Web
33 class HttpRequestStream : Stream
35 byte [] _arrData;
36 int _iLength;
37 int _iOffset;
38 int _iPos;
40 internal HttpRequestStream ()
44 internal HttpRequestStream (byte [] buffer, int offset, int length)
46 Set (buffer, offset, length);
49 void Reset ()
51 Set (null, 0, 0);
54 internal void Set (byte [] buffer, int offset, int length)
56 _iPos = 0;
57 _iOffset = offset;
58 _iLength = length;
59 _arrData = buffer;
62 public override void Flush ()
66 public override void Close ()
68 Reset ();
71 public override int Read (byte [] buffer, int offset, int length)
73 int iBytes = length;
75 if (_iPos < _iOffset)
76 _iPos = _iOffset;
78 if (_iPos + length > _iOffset + _iLength) {
79 iBytes = (int) _iOffset + _iLength - _iPos;
82 if (iBytes <= 0) {
83 return 0;
86 Buffer.BlockCopy (_arrData, _iPos, buffer, offset, iBytes);
87 _iPos += iBytes;
89 return iBytes;
92 public override long Seek (long offset, SeekOrigin origin)
94 switch (origin) {
95 case SeekOrigin.Begin:
96 if (offset > _arrData.Length) {
97 throw new ArgumentException ();
99 _iPos = (int) offset;
100 break;
101 case SeekOrigin.Current:
102 if (((long) _iPos + offset > _arrData.Length) || (_iPos + (int) offset < 0)) {
103 throw new ArgumentException ();
105 _iPos += Convert.ToInt32 (offset);
106 break;
108 case SeekOrigin.End:
109 if (_arrData.Length - offset < 0) {
110 throw new ArgumentException();
113 _iPos = Convert.ToInt32 ( _arrData.Length - offset);
114 break;
117 return (long) _iPos;
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 {
131 get { return true; }
134 public override bool CanSeek {
135 get { return true; }
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); }