| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851 |
- //
- // System.Net.WebConnectionStream
- //
- // Authors:
- // Gonzalo Paniagua Javier ([email protected])
- //
- // (C) 2003 Ximian, Inc (http://www.ximian.com)
- // (C) 2004 Novell, Inc (http://www.novell.com)
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System.IO;
- using System.Text;
- using System.Threading;
- namespace System.Net
- {
- class WebConnectionStream : Stream
- {
- static byte [] crlf = new byte [] { 13, 10 };
- bool isRead;
- WebConnection cnc;
- HttpWebRequest request;
- byte [] readBuffer;
- int readBufferOffset;
- int readBufferSize;
- int stream_length; // -1 when CL not present
- int contentLength;
- int totalRead;
- internal long totalWritten;
- bool nextReadCalled;
- int pendingReads;
- int pendingWrites;
- ManualResetEvent pending;
- bool allowBuffering;
- bool sendChunked;
- MemoryStream writeBuffer;
- bool requestWritten;
- byte [] headers;
- bool disposed;
- bool headersSent;
- object locker = new object ();
- bool initRead;
- bool read_eof;
- bool complete_request_written;
- int read_timeout;
- int write_timeout;
- AsyncCallback cb_wrapper; // Calls to ReadCallbackWrapper or WriteCallbacWrapper
- internal bool IgnoreIOErrors;
- public WebConnectionStream (WebConnection cnc, WebConnectionData data)
- {
- if (data == null)
- throw new InvalidOperationException ("data was not initialized");
- if (data.Headers == null)
- throw new InvalidOperationException ("data.Headers was not initialized");
- if (data.request == null)
- throw new InvalidOperationException ("data.request was not initialized");
- isRead = true;
- cb_wrapper = new AsyncCallback (ReadCallbackWrapper);
- pending = new ManualResetEvent (true);
- this.request = data.request;
- read_timeout = request.ReadWriteTimeout;
- write_timeout = read_timeout;
- this.cnc = cnc;
- string contentType = data.Headers ["Transfer-Encoding"];
- bool chunkedRead = (contentType != null && contentType.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
- string clength = data.Headers ["Content-Length"];
- if (!chunkedRead && clength != null && clength != "") {
- try {
- contentLength = Int32.Parse (clength);
- if (contentLength == 0 && !IsNtlmAuth ()) {
- ReadAll ();
- }
- } catch {
- contentLength = Int32.MaxValue;
- }
- } else {
- contentLength = Int32.MaxValue;
- }
- // Negative numbers?
- if (!Int32.TryParse (clength, out stream_length))
- stream_length = -1;
- }
- public WebConnectionStream (WebConnection cnc, HttpWebRequest request)
- {
- read_timeout = request.ReadWriteTimeout;
- write_timeout = read_timeout;
- isRead = false;
- cb_wrapper = new AsyncCallback (WriteCallbackWrapper);
- this.cnc = cnc;
- this.request = request;
- allowBuffering = request.InternalAllowBuffering;
- sendChunked = request.SendChunked;
- if (sendChunked)
- pending = new ManualResetEvent (true);
- else if (allowBuffering)
- writeBuffer = new MemoryStream ();
- }
- bool IsNtlmAuth ()
- {
- bool isProxy = (request.Proxy != null && !request.Proxy.IsBypassed (request.Address));
- string header_name = (isProxy) ? "Proxy-Authenticate" : "WWW-Authenticate";
- string authHeader = cnc.Data.Headers [header_name];
- return (authHeader != null && authHeader.IndexOf ("NTLM", StringComparison.Ordinal) != -1);
- }
- internal void CheckResponseInBuffer ()
- {
- if (contentLength > 0 && (readBufferSize - readBufferOffset) >= contentLength) {
- if (!IsNtlmAuth ())
- ReadAll ();
- }
- }
- internal HttpWebRequest Request {
- get { return request; }
- }
- internal WebConnection Connection {
- get { return cnc; }
- }
- public override bool CanTimeout {
- get { return true; }
- }
- public override int ReadTimeout {
- get {
- return read_timeout;
- }
- set {
- if (value < -1)
- throw new ArgumentOutOfRangeException ("value");
- read_timeout = value;
- }
- }
- public override int WriteTimeout {
- get {
- return write_timeout;
- }
- set {
- if (value < -1)
- throw new ArgumentOutOfRangeException ("value");
- write_timeout = value;
- }
- }
- internal bool CompleteRequestWritten {
- get { return complete_request_written; }
- }
- internal bool SendChunked {
- set { sendChunked = value; }
- }
- internal byte [] ReadBuffer {
- set { readBuffer = value; }
- }
- internal int ReadBufferOffset {
- set { readBufferOffset = value;}
- }
-
- internal int ReadBufferSize {
- set { readBufferSize = value; }
- }
-
- internal byte[] WriteBuffer {
- get { return writeBuffer.GetBuffer (); }
- }
- internal int WriteBufferLength {
- get { return writeBuffer != null ? (int) writeBuffer.Length : (-1); }
- }
- internal void ForceCompletion ()
- {
- if (!nextReadCalled) {
- if (contentLength == Int32.MaxValue)
- contentLength = 0;
- nextReadCalled = true;
- cnc.NextRead ();
- }
- }
-
- internal void CheckComplete ()
- {
- bool nrc = nextReadCalled;
- if (!nrc && readBufferSize - readBufferOffset == contentLength) {
- nextReadCalled = true;
- cnc.NextRead ();
- }
- }
- internal void ReadAll ()
- {
- if (!isRead || read_eof || totalRead >= contentLength || nextReadCalled) {
- if (isRead && !nextReadCalled) {
- nextReadCalled = true;
- cnc.NextRead ();
- }
- return;
- }
- pending.WaitOne ();
- lock (locker) {
- if (totalRead >= contentLength)
- return;
-
- byte [] b = null;
- int diff = readBufferSize - readBufferOffset;
- int new_size;
- if (contentLength == Int32.MaxValue) {
- MemoryStream ms = new MemoryStream ();
- byte [] buffer = null;
- if (readBuffer != null && diff > 0) {
- ms.Write (readBuffer, readBufferOffset, diff);
- if (readBufferSize >= 8192)
- buffer = readBuffer;
- }
- if (buffer == null)
- buffer = new byte [8192];
- int read;
- while ((read = cnc.Read (request, buffer, 0, buffer.Length)) != 0)
- ms.Write (buffer, 0, read);
- b = ms.GetBuffer ();
- new_size = (int) ms.Length;
- contentLength = new_size;
- } else {
- new_size = contentLength - totalRead;
- b = new byte [new_size];
- if (readBuffer != null && diff > 0) {
- if (diff > new_size)
- diff = new_size;
- Buffer.BlockCopy (readBuffer, readBufferOffset, b, 0, diff);
- }
-
- int remaining = new_size - diff;
- int r = -1;
- while (remaining > 0 && r != 0) {
- r = cnc.Read (request, b, diff, remaining);
- remaining -= r;
- diff += r;
- }
- }
- readBuffer = b;
- readBufferOffset = 0;
- readBufferSize = new_size;
- totalRead = 0;
- nextReadCalled = true;
- }
- cnc.NextRead ();
- }
- void WriteCallbackWrapper (IAsyncResult r)
- {
- WebAsyncResult result = r as WebAsyncResult;
- if (result != null && result.AsyncWriteAll)
- return;
- if (r.AsyncState != null) {
- result = (WebAsyncResult) r.AsyncState;
- result.InnerAsyncResult = r;
- result.DoCallback ();
- } else {
- try {
- EndWrite (r);
- } catch {
- }
- }
- }
- void ReadCallbackWrapper (IAsyncResult r)
- {
- WebAsyncResult result;
- if (r.AsyncState != null) {
- result = (WebAsyncResult) r.AsyncState;
- result.InnerAsyncResult = r;
- result.DoCallback ();
- } else {
- try {
- EndRead (r);
- } catch {
- }
- }
- }
- public override int Read (byte [] buffer, int offset, int size)
- {
- AsyncCallback cb = cb_wrapper;
- WebAsyncResult res = (WebAsyncResult) BeginRead (buffer, offset, size, cb, null);
- if (!res.IsCompleted && !res.WaitUntilComplete (ReadTimeout, false)) {
- nextReadCalled = true;
- cnc.Close (true);
- throw new WebException ("The operation has timed out.", WebExceptionStatus.Timeout);
- }
- return EndRead (res);
- }
- public override IAsyncResult BeginRead (byte [] buffer, int offset, int size,
- AsyncCallback cb, object state)
- {
- if (!isRead)
- throw new NotSupportedException ("this stream does not allow reading");
- if (buffer == null)
- throw new ArgumentNullException ("buffer");
- int length = buffer.Length;
- if (offset < 0 || length < offset)
- throw new ArgumentOutOfRangeException ("offset");
- if (size < 0 || (length - offset) < size)
- throw new ArgumentOutOfRangeException ("size");
- lock (locker) {
- pendingReads++;
- pending.Reset ();
- }
- WebAsyncResult result = new WebAsyncResult (cb, state, buffer, offset, size);
- if (totalRead >= contentLength) {
- result.SetCompleted (true, -1);
- result.DoCallback ();
- return result;
- }
-
- int remaining = readBufferSize - readBufferOffset;
- if (remaining > 0) {
- int copy = (remaining > size) ? size : remaining;
- Buffer.BlockCopy (readBuffer, readBufferOffset, buffer, offset, copy);
- readBufferOffset += copy;
- offset += copy;
- size -= copy;
- totalRead += copy;
- if (size == 0 || totalRead >= contentLength) {
- result.SetCompleted (true, copy);
- result.DoCallback ();
- return result;
- }
- result.NBytes = copy;
- }
- if (cb != null)
- cb = cb_wrapper;
- if (contentLength != Int32.MaxValue && contentLength - totalRead < size)
- size = contentLength - totalRead;
- if (!read_eof) {
- result.InnerAsyncResult = cnc.BeginRead (request, buffer, offset, size, cb, result);
- } else {
- result.SetCompleted (true, result.NBytes);
- result.DoCallback ();
- }
- return result;
- }
- public override int EndRead (IAsyncResult r)
- {
- WebAsyncResult result = (WebAsyncResult) r;
- if (result.EndCalled) {
- int xx = result.NBytes;
- return (xx >= 0) ? xx : 0;
- }
- result.EndCalled = true;
- if (!result.IsCompleted) {
- int nbytes = -1;
- try {
- nbytes = cnc.EndRead (request, result);
- } catch (Exception exc) {
- lock (locker) {
- pendingReads--;
- if (pendingReads == 0)
- pending.Set ();
- }
- nextReadCalled = true;
- cnc.Close (true);
- result.SetCompleted (false, exc);
- result.DoCallback ();
- throw;
- }
- if (nbytes < 0) {
- nbytes = 0;
- read_eof = true;
- }
- totalRead += nbytes;
- result.SetCompleted (false, nbytes + result.NBytes);
- result.DoCallback ();
- if (nbytes == 0)
- contentLength = totalRead;
- }
- lock (locker) {
- pendingReads--;
- if (pendingReads == 0)
- pending.Set ();
- }
- if (totalRead >= contentLength && !nextReadCalled)
- ReadAll ();
- int nb = result.NBytes;
- return (nb >= 0) ? nb : 0;
- }
- void WriteRequestAsyncCB (IAsyncResult r)
- {
- WebAsyncResult result = (WebAsyncResult) r.AsyncState;
- try {
- cnc.EndWrite2 (request, r);
- result.SetCompleted (false, 0);
- if (!initRead) {
- initRead = true;
- WebConnection.InitRead (cnc);
- }
- } catch (Exception e) {
- KillBuffer ();
- nextReadCalled = true;
- cnc.Close (true);
- if (e is System.Net.Sockets.SocketException)
- e = new IOException ("Error writing request", e);
- result.SetCompleted (false, e);
- }
- complete_request_written = true;
- result.DoCallback ();
- }
- public override IAsyncResult BeginWrite (byte [] buffer, int offset, int size,
- AsyncCallback cb, object state)
- {
- if (request.Aborted)
- throw new WebException ("The request was canceled.", null, WebExceptionStatus.RequestCanceled);
- if (isRead)
- throw new NotSupportedException ("this stream does not allow writing");
- if (buffer == null)
- throw new ArgumentNullException ("buffer");
- int length = buffer.Length;
- if (offset < 0 || length < offset)
- throw new ArgumentOutOfRangeException ("offset");
- if (size < 0 || (length - offset) < size)
- throw new ArgumentOutOfRangeException ("size");
- if (sendChunked) {
- lock (locker) {
- pendingWrites++;
- pending.Reset ();
- }
- }
- WebAsyncResult result = new WebAsyncResult (cb, state);
- if (!sendChunked)
- CheckWriteOverflow (request.ContentLength, totalWritten, size);
- if (allowBuffering && !sendChunked) {
- if (writeBuffer == null)
- writeBuffer = new MemoryStream ();
- writeBuffer.Write (buffer, offset, size);
- totalWritten += size;
- if (request.ContentLength > 0 && totalWritten == request.ContentLength) {
- try {
- result.AsyncWriteAll = true;
- result.InnerAsyncResult = WriteRequestAsync (new AsyncCallback (WriteRequestAsyncCB), result);
- if (result.InnerAsyncResult == null) {
- if (!result.IsCompleted)
- result.SetCompleted (true, 0);
- result.DoCallback ();
- }
- } catch (Exception exc) {
- result.SetCompleted (true, exc);
- result.DoCallback ();
- }
- } else {
- result.SetCompleted (true, 0);
- result.DoCallback ();
- }
- return result;
- }
- AsyncCallback callback = null;
- if (cb != null)
- callback = cb_wrapper;
- if (sendChunked) {
- WriteRequest ();
- string cSize = String.Format ("{0:X}\r\n", size);
- byte [] head = Encoding.ASCII.GetBytes (cSize);
- int chunkSize = 2 + size + head.Length;
- byte [] newBuffer = new byte [chunkSize];
- Buffer.BlockCopy (head, 0, newBuffer, 0, head.Length);
- Buffer.BlockCopy (buffer, offset, newBuffer, head.Length, size);
- Buffer.BlockCopy (crlf, 0, newBuffer, head.Length + size, crlf.Length);
- buffer = newBuffer;
- offset = 0;
- size = chunkSize;
- }
- try {
- result.InnerAsyncResult = cnc.BeginWrite (request, buffer, offset, size, callback, result);
- } catch (Exception) {
- if (!IgnoreIOErrors)
- throw;
- result.SetCompleted (true, 0);
- result.DoCallback ();
- }
- totalWritten += size;
- return result;
- }
- void CheckWriteOverflow (long contentLength, long totalWritten, long size)
- {
- if (contentLength == -1)
- return;
- long avail = contentLength - totalWritten;
- if (size > avail) {
- KillBuffer ();
- nextReadCalled = true;
- cnc.Close (true);
- throw new ProtocolViolationException (
- "The number of bytes to be written is greater than " +
- "the specified ContentLength.");
- }
- }
- public override void EndWrite (IAsyncResult r)
- {
- if (r == null)
- throw new ArgumentNullException ("r");
- WebAsyncResult result = r as WebAsyncResult;
- if (result == null)
- throw new ArgumentException ("Invalid IAsyncResult");
- if (result.EndCalled)
- return;
- result.EndCalled = true;
- if (result.AsyncWriteAll) {
- result.WaitUntilComplete ();
- if (result.GotException)
- throw result.Exception;
- return;
- }
- if (allowBuffering && !sendChunked)
- return;
- if (result.GotException)
- throw result.Exception;
- try {
- cnc.EndWrite2 (request, result.InnerAsyncResult);
- result.SetCompleted (false, 0);
- result.DoCallback ();
- } catch (Exception e) {
- if (IgnoreIOErrors)
- result.SetCompleted (false, 0);
- else
- result.SetCompleted (false, e);
- result.DoCallback ();
- if (!IgnoreIOErrors)
- throw;
- } finally {
- if (sendChunked) {
- lock (locker) {
- pendingWrites--;
- if (pendingWrites == 0)
- pending.Set ();
- }
- }
- }
- }
-
- public override void Write (byte [] buffer, int offset, int size)
- {
- AsyncCallback cb = cb_wrapper;
- WebAsyncResult res = (WebAsyncResult) BeginWrite (buffer, offset, size, cb, null);
- if (!res.IsCompleted && !res.WaitUntilComplete (WriteTimeout, false)) {
- KillBuffer ();
- nextReadCalled = true;
- cnc.Close (true);
- throw new IOException ("Write timed out.");
- }
- EndWrite (res);
- }
- public override void Flush ()
- {
- }
- internal void SetHeadersAsync (byte[] buffer, WebAsyncResult result)
- {
- if (headersSent)
- return;
- headers = buffer;
- long cl = request.ContentLength;
- string method = request.Method;
- bool no_writestream = (method == "GET" || method == "CONNECT" || method == "HEAD" ||
- method == "TRACE");
- bool webdav = (method == "PROPFIND" || method == "PROPPATCH" || method == "MKCOL" ||
- method == "COPY" || method == "MOVE" || method == "LOCK" ||
- method == "UNLOCK");
- if (sendChunked || cl > -1 || no_writestream || webdav) {
- headersSent = true;
- try {
- result.InnerAsyncResult = cnc.BeginWrite (request, headers, 0, headers.Length, new AsyncCallback(SetHeadersCB), result);
- if (result.InnerAsyncResult == null) {
- // when does BeginWrite return null? Is the case when the request is aborted?
- if (!result.IsCompleted)
- result.SetCompleted (true, 0);
- result.DoCallback ();
- }
- } catch (Exception exc) {
- result.SetCompleted (true, exc);
- result.DoCallback ();
- }
- }
- }
- void SetHeadersCB (IAsyncResult r)
- {
- WebAsyncResult result = (WebAsyncResult) r.AsyncState;
- result.InnerAsyncResult = null;
- try {
- cnc.EndWrite2 (request, r);
- result.SetCompleted (false, 0);
- if (!initRead) {
- initRead = true;
- WebConnection.InitRead (cnc);
- }
- long cl = request.ContentLength;
- if (!sendChunked && cl == 0)
- requestWritten = true;
- } catch (WebException e) {
- result.SetCompleted (false, e);
- } catch (Exception e) {
- result.SetCompleted (false, new WebException ("Error writing headers", e, WebExceptionStatus.SendFailure));
- }
- result.DoCallback ();
- }
- internal bool RequestWritten {
- get { return requestWritten; }
- }
- IAsyncResult WriteRequestAsync (AsyncCallback cb, object state)
- {
- requestWritten = true;
- byte [] bytes = writeBuffer.GetBuffer ();
- int length = (int) writeBuffer.Length;
- // Headers already written to the stream
- return (length > 0) ? cnc.BeginWrite (request, bytes, 0, length, cb, state) : null;
- }
- internal void WriteRequest ()
- {
- if (requestWritten)
- return;
- requestWritten = true;
- if (sendChunked)
- return;
- if (!allowBuffering || writeBuffer == null)
- return;
- byte [] bytes = writeBuffer.GetBuffer ();
- int length = (int) writeBuffer.Length;
- if (request.ContentLength != -1 && request.ContentLength < length) {
- nextReadCalled = true;
- cnc.Close (true);
- throw new WebException ("Specified Content-Length is less than the number of bytes to write", null,
- WebExceptionStatus.ServerProtocolViolation, null);
- }
- if (!headersSent) {
- string method = request.Method;
- bool no_writestream = (method == "GET" || method == "CONNECT" || method == "HEAD" ||
- method == "TRACE");
- if (!no_writestream)
- request.InternalContentLength = length;
- byte[] requestHeaders = request.GetRequestHeaders ();
- WebAsyncResult ar = new WebAsyncResult (null, null);
- SetHeadersAsync (requestHeaders, ar);
- ar.AsyncWaitHandle.WaitOne ();
- if (ar.Exception != null)
- throw ar.Exception;
- }
- if (cnc.Data.StatusCode != 0 && cnc.Data.StatusCode != 100)
- return;
-
- IAsyncResult result = null;
- if (length > 0)
- result = cnc.BeginWrite (request, bytes, 0, length, null, null);
-
- if (!initRead) {
- initRead = true;
- WebConnection.InitRead (cnc);
- }
- if (length > 0)
- complete_request_written = cnc.EndWrite (request, result);
- else
- complete_request_written = true;
- }
- internal void InternalClose ()
- {
- disposed = true;
- }
- public override void Close ()
- {
- if (sendChunked) {
- if (disposed)
- return;
- disposed = true;
- pending.WaitOne ();
- byte [] chunk = Encoding.ASCII.GetBytes ("0\r\n\r\n");
- string err_msg = null;
- cnc.Write (request, chunk, 0, chunk.Length, ref err_msg);
- return;
- }
- if (isRead) {
- if (!nextReadCalled) {
- CheckComplete ();
- // If we have not read all the contents
- if (!nextReadCalled) {
- nextReadCalled = true;
- cnc.Close (true);
- }
- }
- return;
- } else if (!allowBuffering) {
- complete_request_written = true;
- if (!initRead) {
- initRead = true;
- WebConnection.InitRead (cnc);
- }
- return;
- }
- if (disposed || requestWritten)
- return;
- long length = request.ContentLength;
- if (!sendChunked && length != -1 && totalWritten != length) {
- IOException io = new IOException ("Cannot close the stream until all bytes are written");
- nextReadCalled = true;
- cnc.Close (true);
- throw new WebException ("Request was cancelled.", io, WebExceptionStatus.RequestCanceled);
- }
- // Commented out the next line to fix xamarin bug #1512
- //WriteRequest ();
- disposed = true;
- }
- internal void KillBuffer ()
- {
- writeBuffer = null;
- }
- public override long Seek (long a, SeekOrigin b)
- {
- throw new NotSupportedException ();
- }
-
- public override void SetLength (long a)
- {
- throw new NotSupportedException ();
- }
-
- public override bool CanSeek {
- get { return false; }
- }
- public override bool CanRead {
- get { return !disposed && isRead; }
- }
- public override bool CanWrite {
- get { return !disposed && !isRead; }
- }
- public override long Length {
- get {
- if (!isRead)
- throw new NotSupportedException ();
- return stream_length;
- }
- }
- public override long Position {
- get { throw new NotSupportedException (); }
- set { throw new NotSupportedException (); }
- }
- }
- }
|