2 // System.Web.HttpWriter.cs
6 // Miguel de Icaza (miguel@novell.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Globalization;
34 using System.Runtime.InteropServices;
35 using System.Security.Permissions;
37 namespace System.Web {
39 // CAS - no InheritanceDemand here as the class is sealed
40 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 public sealed class HttpWriter : TextWriter {
42 HttpResponseStream output_stream;
43 HttpResponse response;
46 internal HttpWriter (HttpResponse response)
48 this.response = response;
49 encoding = response.ContentEncoding;
50 output_stream = response.output_stream;
53 public override Encoding Encoding {
59 internal void SetEncoding (Encoding new_encoding)
61 encoding = new_encoding;
64 public Stream OutputStream {
71 // Flush data, and closes socket
73 public override void Close ()
75 output_stream.Close ();
78 public override void Flush ()
80 output_stream.Flush ();
83 public override void Write (char ch)
85 Write (new string (ch, 1));
88 public override void Write (object obj)
93 Write (obj.ToString ());
96 public override void Write (string s)
101 byte [] xx = encoding.GetBytes (s);
103 output_stream.Write (xx, 0, xx.Length);
111 public override void Write (char [] buffer, int index, int count)
113 byte [] xx = encoding.GetBytes (buffer, index, count);
114 output_stream.Write (xx, 0, xx.Length);
122 static byte [] newline = new byte [2] { 13, 10 };
124 public override void WriteLine ()
126 output_stream.Write (newline, 0, 2);
134 public void WriteString (string s, int index, int count)
136 char [] a = s.ToCharArray (index, count);
138 byte [] xx = encoding.GetBytes (a, 0, count);
140 output_stream.Write (xx, 0, xx.Length);
148 public void WriteBytes (byte [] buffer, int index, int count)
150 output_stream.Write (buffer, index, count);