Skip to content

Instantly share code, notes, and snippets.

@bjartwolf
Last active August 29, 2015 14:00
Show Gist options
  • Save bjartwolf/11355435 to your computer and use it in GitHub Desktop.
Save bjartwolf/11355435 to your computer and use it in GitHub Desktop.
streams to make caps
using System;
using System.IO;
using System.Text;
namespace HelloWorldMiddleWare2
{
class CapsStream: Stream
{
private Stream _stream;
private Decoder _decoder;
public CapsStream(Stream stream)
{
_stream = stream;
_decoder = Encoding.UTF8.GetDecoder();
}
public override void Flush()
{
throw new NotImplementedException();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
int charCount = _decoder.GetCharCount(buffer, offset, count);
var chars = new Char[charCount];
int charsDecodedCount = _decoder.GetChars(buffer, offset, count, chars, 0);
var caps = new string(chars).ToUpper();
var capsBuffer = Encoding.UTF8.GetBytes(caps);
_stream.Write(capsBuffer,0,capsBuffer.Length);
}
public override bool CanRead
{
get { return false; }
}
public override bool CanSeek
{
get { throw new NotImplementedException(); }
}
public override bool CanWrite
{
get { return true; }
}
public override long Length
{
get { throw new NotImplementedException(); }
}
public override long Position { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment