|
using System;
using System.IO;
namespace CXSL
{
/// cxslFilter is a responce filter,
/// used to cache the output stream into a temporary memory.
/// it doesn't fordward the output to the client.
public class cxslFilter : Stream
{
public Stream _sink;
private long _position;
private string _outstr;
/// Construction.
/// sink is the previous filter
public cxslFilter(Stream sink)
{
_sink = sink;
_outstr = "";
}
// member of Stream must be overriden.
public override bool CanRead
{
get { return true; }
}
// member of Stream must be overriden.
public override bool CanSeek
{
get { return true; }
}
// member of Stream must be overriden.
public override bool CanWrite
{
get { return true; }
}
// member of Stream must be overriden.
public override long Length
{
get { return 0; }
}
// member of Stream must be overriden.
public override long Position
{
get { return _position; }
set { _position = value; }
}
// member of Stream must be overriden.
public override long Seek(long offset, System.IO.SeekOrigin direction)
{
return _sink.Seek(offset, direction);
}
// member of Stream must be overriden.
public override void SetLength(long length)
{
_sink.SetLength(length);
}
// member of Stream must be overriden.
public override void Close()
{
_sink.Close();
}
// member of Stream must be overriden.
public override void Flush()
{
_sink.Flush();
}
// member of Stream must be overriden.
public override int Read(byte[] buffer, int offset, int count)
{
return _sink.Read(buffer, offset, count);
}
// member of Stream must be overriden.
public String GetBuffer()
{
return _outstr;
}
/// The Write method does the caching.
public override void Write(byte[] buffer, int offset, int count)
{
// cache the output into _outstr
System.Text.Encoding Enc=System.Text.Encoding.Default;
_outstr += Enc.GetString(buffer,offset,count);
// we DO NOT fordward the output to the previous filter
//_sink.Write(data, 0, count);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.