summaryrefslogtreecommitdiffstats
path: root/source/Janrain.OpenId/CustomTraceStream.cs
blob: 7a436cafa785735b7e22a5314f9c3adbe1015374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;

namespace Janrain.OpenId
{
    public class CustomTraceStream : MemoryStream
    {
        // Private members
        private Stream m_outputStream;
        
        private string savedPageOutput;

        // Ctor
        public CustomTraceStream(Stream outputStream)
        {
            m_outputStream = outputStream;
        }

        public string SavedPageOutput
        {
            get { return savedPageOutput; }
        }

        public void ClearSavedPageOutput()
        {
            savedPageOutput = "";
        }


        // Write method does it
        public override void Write(byte[] buffer, int offset, int count)
        {
            // Gets a string out of bytes
            Encoding enc = HttpContext.Current.Response.ContentEncoding;
            string theText = enc.GetString(buffer, offset, count);
            
            // save to our local string
            savedPageOutput = SavedPageOutput + theText;;

            // Write to the original stream
            byte[] data = enc.GetBytes(theText);
            m_outputStream.Write(data, 0, theText.Length);
        }
    }
}