///<summary> ///When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. ///</summary> /// ///<param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream. </param> ///<param name="count">The number of bytes to be written to the current stream. </param> ///<param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream. </param> ///<exception cref="T:System.IO.IOException">An I/O error occurs. </exception> ///<exception cref="T:System.NotSupportedException">The stream does not support writing. </exception> ///<exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception> ///<exception cref="T:System.ArgumentNullException">buffer is null. </exception> ///<exception cref="T:System.ArgumentException">The sum of offset and count is greater than the buffer length. </exception> ///<exception cref="T:System.ArgumentOutOfRangeException">offset or count is negative. </exception><filterpriority>1</filterpriority> public override void Write(byte[] buffer, int offset, int count) { OriginalMemoryStream.Write(buffer, offset, count); CheckHtmlAndEncoding(); if (_isHtml) { //Get a string version of the buffer string szBuffer = _encoding.GetString(buffer, offset, count); OOutput.Append(szBuffer); } }
private void FlushShrunk() { if (Sink != null) { CheckHtmlAndEncoding(); byte[] data = null; bool handled = false; if (_isHtml) { //Get back the complete response for the client string szCompleteBuffer = OOutput.ToString(); szCompleteBuffer = Process(szCompleteBuffer, out handled); data = _encoding.GetBytes(szCompleteBuffer); } if (!handled) { data = OriginalMemoryStream.ToArray(); OriginalMemoryStream.Close(); } try { Sink.Write(data, 0, data.Length); } catch { if (HttpContext.Current.IsDebuggingEnabled) { throw; } } } OriginalMemoryStream = null; OOutput.Length = 0; }