예제 #1
0
 public override Stream openStream()
 {
     //This is a bit hacky, but since the StreamReader defaults to utf-8 we don't actually have to include
     //the preamble in those strings. This fixes problems with other libraries (like libRocket) that cannot
     //deal with the preamble, but expect UTF-8.
     if (TextEncoding == Encoding.UTF8)
     {
         return(new MemoryStream(TextEncoding.GetBytes(CachedString)));
     }
     else
     {
         byte[]       preamble = TextEncoding.GetPreamble();
         byte[]       data     = TextEncoding.GetBytes(CachedString);
         MemoryStream ms       = new MemoryStream(preamble.Length + data.Length);
         ms.Write(preamble, 0, preamble.Length);
         ms.Write(data, 0, data.Length);
         ms.Seek(0, SeekOrigin.Begin);
         return(ms);
     }
 }