using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
namespace DreamZone.Core
{
/// <summary>
/// CG2BFilter 的摘要说明。
/// </summary>
public class CG2BFilter : Stream
{
Stream responseStream;
long position;
StringBuilder responseHtml;
public CG2BFilter (Stream inputStream)
{
responseStream = inputStream;
responseHtml = new StringBuilder ();
}
#region Filter overrides
public override bool CanRead
{
get { return true;}
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Close()
{
responseStream.Close ();
}
public override void Flush()
{
responseStream.Flush ();
}
public override long Length
{
get { return 0; }
}
public override long Position
{
get { return position; }
set { position = value; }
}
public override long Seek(long offset, SeekOrigin origin)
{
return responseStream.Seek (offset, origin);
}
public override void SetLength(long length)
{
responseStream.SetLength (length);
}
public override int Read(byte[] buffer, int offset, int count)
{
return responseStream.Read (buffer, offset, count);
}
#endregion
#region 转换任务
public override void Write(byte[] buffer, int offset, int count)
{
string strBuffer = System.Text.UTF8Encoding.UTF8.GetString (buffer, offset, count);
string finalHtml = Simplified2Traditional(strBuffer);
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes (finalHtml);
responseStream.Write (data, 0, data.Length);
}
#endregion
#region 自定义函数
public string Traditional2Simplified( string str)
{ //繁体转简体
return(Microsoft.VisualBasic.Strings.StrConv(str, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese,0));
}
public string Simplified2Traditional( string str)
{ //简体转繁体
return(Microsoft.VisualBasic.Strings.StrConv(str as String, Microsoft.VisualBasic.VbStrConv.TraditionalChinese,0));
}
#endregion
}
}
调用只要一行代码:
Response.Filter = new DreamZone.Core.CG2BFilter(Response.Filter);//设置筛选器