Advertisement
Guest User

XML Transponder

a guest
Mar 19th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace iOSTest
  5. {
  6.     public class TextTransponder : MemoryStream
  7.     {
  8.         private static readonly bool[] _charTable = new bool[256];
  9.         static TextTransponder()
  10.         {
  11.             int len = _charTable.Length;
  12.             while (len > 0) _charTable [--len] = true;
  13.  
  14.             len = 0;
  15.             while (len < 8) _charTable [len++] = false;
  16.  
  17.             len = 14;
  18.             while (len < 32) _charTable [len++] = false;
  19.  
  20.             _charTable [11] = _charTable [12] = false;
  21.         }
  22.  
  23.         public TextTransponder (FileStream src) : base(src.Length)
  24.         {
  25.             long oldPos = src.Position;
  26.             src.Position = 0;
  27.  
  28.             int len = src.Length;
  29.             while (len-- > 0) {
  30.                 byte c = src.ReadByte ();
  31.                 if (_charTable [c])
  32.                     this.WriteByte (c);
  33.             }
  34.  
  35.             src.Position = oldPos;
  36.             this.Position = 0;
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement