예제 #1
0
 public static byte ReadByte(Stream s)
 {
     int v = s.ReadByte();
     if (v == -1)
         throw new Exception("IOException: EOF");
     return (byte)v;
 }
예제 #2
0
 public static int InternalReadByte(Stream s)
 {
     int v = s.ReadByte();
     if (v == -1)
         throw new Exception("IOException: EOF");
     return v;
 }
예제 #3
0
 public static uint ReadUInt32(Stream s)
 {
     int a = s.ReadByte();
     int b = s.ReadByte();
     int c = s.ReadByte();
     int d = InternalReadByte(s);
     return (uint)((a << 24) | (b << 16) | (c << 8) | d);
 }
예제 #4
0
 public static ushort ReadUInt16(Stream s)
 {
     int a = s.ReadByte();
     int b = InternalReadByte(s);
     return (ushort)((a << 8) | b);
 }
예제 #5
0
 public static char ReadChar(Stream s)
 {
     int a = s.ReadByte();
     int b = InternalReadByte(s);
     return (char)((a << 8) | b);
 }
예제 #6
0
 public static sbyte ReadSByte(Stream s)
 {
     int v = s.ReadByte();
     return (sbyte)v;
 }
예제 #7
0
 private static int InternalReadInt16(Stream s)
 {
     int a = s.ReadByte();
     int b = InternalReadByte(s);
     return ((a << 8) | b);
 }
예제 #8
0
 private static int ReadUtfChar(Stream s, StringBuilder sb)
 {
     int a = InternalReadByte(s);
     if ((a & 0x80) == 0)
     {
         sb.Append((char)a);
         return 1;
     }
     if ((a & 0xe0) == 0xb0)
     {
         int b = InternalReadByte(s);
         sb.Append((char)(((a & 0x1F) << 6) | (b & 0x3F)));
         return 2;
     }
     if ((a & 0xf0) == 0xe0)
     {
         int b = s.ReadByte();
         int c = InternalReadByte(s);
         sb.Append((char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F)));
         return 3;
     }
     throw new Exception("IOException: UTFDataFormat:");
 }