ReadChar() public method

public ReadChar ( ) : char
return char
Example #1
0
        static void Main(string[] args)
        {
            using (BinaryReader b = new BinaryReader(File.Open("file.top", FileMode.Open)))
            {
                int pos = 0;
                int length = (int)b.BaseStream.Length;

                char ch0 = b.ReadChar();
                char ch1 = b.ReadChar();
                char ch2 = b.ReadChar();

                byte verr = b.ReadByte();
                /*Int32 tripCount =  b.ReadInt32();
                for (int i = 0; i < tripCount; i++)
                {
                    Int64 time = b.ReadInt64();
                    string comment = b.ReadString();
                    Int16 declination = b.ReadInt16();
                }
                pos += sizeof(char) * 3;*/
                TopFile file = new TopFile(b);

            }

            byte[] fajl = File.ReadAllBytes("file.top");

            /*          char ch0 = Convert.ToChar(fajl[0]);
            char ch1 = Convert.ToChar(fajl[1]);
            char ch2 = Convert.ToChar(fajl[2]);
            byte ver = fajl[3];*/
            //TopFile file = new TopFile(fajl, 4);
        }
Example #2
0
        public static void ShareMemory()
        {
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(MmfName, 10000))
            {
                Console.WriteLine("Process A started.");
                bool mutexCreated;
                var mutex = new Mutex(true, MmfMutex, out mutexCreated);

                using (MemoryMappedViewStream stream = mmf.CreateViewStream())
                {
                    var writer = new BinaryWriter(stream);
                    writer.Write('a');
                }
                mutex.ReleaseMutex();

                Console.WriteLine("Please start process B. Once it's done press ENTER.");
                Console.ReadLine();

                mutex.WaitOne();
                using (MemoryMappedViewStream stream = mmf.CreateViewStream())
                {
                    var reader = new BinaryReader(stream);
                    Console.WriteLine("Process A : {0}", reader.ReadChar());
                    Console.WriteLine("Process B : {0}", reader.ReadChar());
                    Console.ReadLine();
                }
                mutex.ReleaseMutex();
            }
        }
Example #3
0
 public static void GenerateDonorGenomeFromReferenceGenome(string refGenomeFile, string donorGenomeFile)
 {
     var rng = new Random();
     using (var refFile = File.OpenRead(refGenomeFile))
     using (var donorFile = File.Open(donorGenomeFile, FileMode.Create))
     {
         var reader = new BinaryReader(refFile);
         var writer = new BinaryWriter(donorFile);
         for (long i = 0; i < refFile.Length; i++)
         {
             var randomNumber = rng.NextDouble();
             if (randomNumber < SnpDensity)
             {
                 var readChar = reader.ReadChar();
                 if (readChar == 'A')
                     writer.Write('C');
                 else if (readChar == 'C')
                     writer.Write('G');
                 else if (readChar == 'G')
                     writer.Write('T');
                 else if (readChar == 'T')
                     writer.Write('A');
                 else throw new Exception();
             }
             else
             {
                 writer.Write(reader.ReadChar());
             }
         }
     }
 }
Example #4
0
        public static string[] ReadAllLines(BinaryReader reader)
        {
            List<string> strings = new List<string>();
            StringBuilder temp = new StringBuilder();

            char lastChar = reader.ReadChar();
            // an EndOfStreamException here would propogate to the caller

            try
            {
                while (true)
                {
                    char newChar = reader.ReadChar();
                    if (lastChar == '\r' && newChar == '\n')
                    {
                        strings.Add(temp.ToString());
                    }

                    temp.Append(lastChar);
                    lastChar = newChar;
                }
            }
            catch (EndOfStreamException)
            {
                temp.Append(lastChar);
                strings.Add(temp.ToString());
                return strings.ToArray();
            }
        }
Example #5
0
        public static SortedDictionary<string, Stream> GetEntries(string archive)
        {
            SortedDictionary<string, Stream> result = new SortedDictionary<string, Stream>();
            BinaryReader br = new BinaryReader(File.OpenRead(archive));
            StringBuilder sb = new StringBuilder();

            var magic = new String(br.ReadChars(4));
            if (magic != "BIG4" && magic != "BIGF")
            {
                throw new BigLoadException(archive + " is not a valid BIG4 File");
            }

            UInt32 filesize = br.ReadUInt32();
            UInt32 numEntries = ReadUint32LE(br);
            UInt32 offset = ReadUint32LE(br);

            for (var i = 0;i<numEntries;++i)
            {
                var entryOffset = ReadUint32LE(br);
                var entrySize = ReadUint32LE(br);

                char c = br.ReadChar();
                while(c!=0)
                {
                    sb.Append(c);
                    c = br.ReadChar();
                }
                var bs = new BigStream(br.BaseStream, entryOffset, entrySize, sb.ToString());
                result.Add(sb.ToString(), bs);
                sb.Clear();
            }

            return result;
        }
Example #6
0
        // --- Static Methods ---
        // Loads in the team
        public static Team load(string filename, GameExt game)
        {
            // Variables
            BinaryReader	reader=	new BinaryReader(File.OpenRead(filename));
            Team	team=	new Team(game, true);
            int	size;
            int	passiveSize=	0;

            team.money=	reader.ReadInt32();
            size=	reader.ReadInt32();
            for(int i= 0; i< size; i++)
            {
                team.units.add(
                    new Unit(
                        reader.ReadString(),
                        reader.ReadString(),
                        reader.ReadString(),
                        game,
                        game.registry.get<ProfessionRegistry>().get(reader.ReadChar()+""+reader.ReadChar()+""+reader.ReadChar()+""+reader.ReadChar())
                    )
                );
                team.units.items[i].statVariance=	new BaseStats(reader.ReadUInt64());
                team.units.items[i].setExp(reader.ReadInt32());
                passiveSize=	reader.ReadInt32();
                for(int k= 0; k< passiveSize; k++)
                {
                    team.units.items[i].assignPassive(
                        team.units.items[i].decryptPassive(reader.ReadChar()),
                        k
                    );
                }
            }

            return team;
        }
Example #7
0
 public static BARFile Load(string filename)
 {
     if (!File.Exists(filename)) return null;
     var file = File.OpenRead(filename);
     var bar = new BARFile() {
         stream = file,
         SourceFilename = filename,
     };
     var reader = new BinaryReader(file);
     reader.Read(bar.Id = new byte[8], 0, 8);
     int unknown = reader.ReadInt32();
     int entryC = reader.ReadInt32();
     bar.DirectorySize = reader.ReadInt32();
     bar.DirectoryOffset = reader.ReadInt32();
     int unknown2 = reader.ReadInt32();
     file.Seek(bar.DirectoryOffset, SeekOrigin.Begin);
     int[] offsets = new int[entryC];
     for (int o = 0; o < offsets.Length; ++o) offsets[o] = reader.ReadInt32();
     for (int e = 0; e < entryC; ++e) {
         Entry entry = new Entry();
         entry.Offset = reader.ReadInt32();
         entry.Size = reader.ReadInt32();
         entry.Size2 = reader.ReadInt32();
         byte b0 = reader.ReadByte(),
             b1 = reader.ReadByte(),
             b2 = reader.ReadByte(),
             b3 = reader.ReadByte();
         if (b3 != 0) file.Position += 4;
         for (var c = reader.ReadChar(); c != '\0'; c = reader.ReadChar()) {
             entry.Name += c;
         }
         bar.entries.Add(entry);
     }
     return bar;
 }
Example #8
0
	  	public void Read(BinaryReader reader)
	  	{
	  		ID0 = reader.ReadChar();
	  		ID1 = reader.ReadChar();
	  		ID2 = reader.ReadChar();
	  		ID3 = reader.ReadChar();
	  		length = NetworkToHostOrder(reader.ReadUInt32());
	  	}
Example #9
0
        public static XmlDocument DecompressXMLDocument(Stream ms)
        {
            BinaryReader br = new BinaryReader(ms);
            StringBuilder sb = new StringBuilder();

            while (br.PeekChar() != (int)BYTE_TAGS.DEFINE_ELEMENTS_BEGIN)
            {
                br.ReadChar();
            }


            //Load elemental translations
            br.ReadChar();
            bool elem_use_short = br.ReadByte() == (byte)2;
            Dictionary<int, string> elementTrans = new Dictionary<int, string>();
            int id;
            int len;
            while (true)
            {
                if (br.ReadByte() == (int)BYTE_TAGS.DEFINE_ELEMENTS_END)
                    break;
                if (elem_use_short)
                    id = (int)br.ReadInt16();
                else
                    id = (int)br.ReadByte();
                len = br.ReadInt32();
                elementTrans.Add(id, System.Text.ASCIIEncoding.ASCII.GetString(br.ReadBytes(len)));
            }
            
            //Load attribute translations
            br.ReadByte();
            bool att_use_short = br.ReadByte() == (byte)2;
            Dictionary<int, string> attTrans = new Dictionary<int, string>();
            while (true)
            {
                if (br.ReadByte() == (byte)BYTE_TAGS.DEFINE_ATTRIBUTES_END)
                    break;
                if (att_use_short)
                    id = (int)br.ReadInt16();
                else
                    id = (int)br.ReadByte();
                len = br.ReadInt32();
                attTrans.Add(id, System.Text.ASCIIEncoding.ASCII.GetString(br.ReadBytes(len)));
            }

            //begin loading and translation of the document back to xml
            br.ReadByte();
            XmlDocument ret = new XmlDocument();
            while (br.BaseStream.Position < br.BaseStream.Length - 1)
            {
                XmlElement tmp = LoadElement(ref br, ret,att_use_short,elem_use_short,elementTrans,attTrans);
                if (tmp != null)
                    ret.AppendChild(tmp);
            }

            return ret;
        }
 public Int32 getShMemData(int offset = 0)
 {
     using (MemoryMappedViewStream stream = mmf.CreateViewStream())
     {
         BinaryReader reader = new BinaryReader(stream);
         for (int i = 0; i < offset; i++) reader.ReadChar();
         return reader.ReadChar();
     }
 }
Example #11
0
        public DxfBinaryReader(BinaryReader reader)
        {
            _reader = reader;

            // swallow next two characters
            var sub = reader.ReadChar();
            Debug.Assert(sub == 0x1A);
            var nul = reader.ReadChar();
            Debug.Assert(nul == 0x00);
        }
Example #12
0
        public static DDTImage Load(Stream file)
        {
            long beg = file.Position;
            var reader = new BinaryReader(file);
            string header = "";
            for (int h = 0; h < 3; ++h) header += reader.ReadChar();
            if (header != "RTS") throw new InvalidDataException();
            int version = (int)reader.ReadChar() - (int)'0';
            if (version == 3) {
                var img = new DDTImage();
                var serializer = new SerialReader(new BinaryReader(file));
                SerializeHeader(ref img.Header, serializer);

                int numColors = (img.Palette != null ? img.Palette.Length : 0);
                int[] paletteOffs = new int[5];
                if (img.Header.Format == ImageHeader.FormatE.Palette) {
                    // TODO: paletteOffs[img.Header.AlphaBits] = palette offset
                    serializer.Serialize(ref numColors);
                    int unknown02 = 0;
                    int palette15Off = 0;
                    serializer.Serialize(ref unknown02);
                    serializer.Serialize(ref paletteOffs[0]);       //16
                    serializer.Serialize(ref palette15Off);
                    serializer.Serialize(ref paletteOffs[1]);       //15b
                    serializer.Serialize(ref paletteOffs[4]);       //12
                }

                List<Tuple<int, int>> images = new List<Tuple<int, int>>();
                for (int l = 0; l < img.Header.MipLevels; ++l) {
                    int off = reader.ReadInt32();
                    int len = reader.ReadInt32();
                    images.Add(new Tuple<int,int>(off, len));
                }

                if (img.Header.Format == ImageHeader.FormatE.Palette) {
                    file.Seek(beg + paletteOffs[img.Header.AlphaBits], SeekOrigin.Begin);
                    byte[] paletteData = new byte[numColors * 2];
                    file.Read(paletteData, 0, paletteData.Length);

                    img.Palette = new Pixel[numColors];
                    switch (img.Header.AlphaBits) {
                        case 0: Convert565ToRGB(paletteData, 0, img.Palette); break;
                        case 1: Convert555ToRGB(paletteData, 0, img.Palette); break;
                        case 4: Convert444ToRGB(paletteData, 0, img.Palette); break;
                    }
                }

                file.Seek(beg + images[0].Item1, SeekOrigin.Begin);
                byte[] bytes = new byte[images[0].Item2];
                reader.Read(bytes, 0, bytes.Length);
                img.PixelData = bytes;
                return img;
            }
            return null;
        }
Example #13
0
 public static string ReadString(BinaryReader stream)
 {
     string r = "";
     char c = stream.ReadChar();
     while (c != 0xFF)
     {
         r += c;
         c = stream.ReadChar();
     }
     return r;
 }
        public byte[] ExtractAudio(Stream stream)
        {
            stream.Position = 0;

            var reader = new BinaryReader(stream);

            // Is stream a Flash Video stream
            if (reader.ReadChar() != 'F' || reader.ReadChar() != 'L' || reader.ReadChar() != 'V')
                throw new IOException("The file is not a FLV file.");

            // Is audio stream exists in the video stream
            var version = reader.ReadByte();
            var exists = reader.ReadByte();

            if ((exists != 5) && (exists != 4))
                throw new IOException("No Audio Stream");

            reader.ReadInt32(); // data offset of header. ignoring

            var output = new List<byte>();

            while (true)
            {
                try
                {
                    reader.ReadInt32(); // PreviousTagSize0 skipping

                    var tagType = reader.ReadByte();

                    while (tagType != 8)
                    {
                        var skip = ReadNext3Bytes(reader) + 11;
                        reader.BaseStream.Position += skip;

                        tagType = reader.ReadByte();
                    }

                    var DataSize = ReadNext3Bytes(reader);

                    reader.ReadInt32(); //skip timestamps 
                    ReadNext3Bytes(reader); // skip streamID
                    reader.ReadByte(); // skip audio header

                    for (int i = 0; i < DataSize - 1; i++)
                        output.Add(reader.ReadByte());
                }
                catch
                {
                    break;
                }
            }

            return output.ToArray();
        }
Example #15
0
 private string ReadLine(BinaryReader binReader)
 {
     StringBuilder result = new StringBuilder();
     char lastChar = binReader.ReadChar();
     while (lastChar != '\n')
     {
         result.Append(lastChar);
         lastChar = binReader.ReadChar();
     }
     return result.ToString();
 }
Example #16
0
        /// <summary>
        /// Reads the specified PGM stream and returns a Bitmap.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        /// <exception cref="BadImageFormatException">PGM Magic Number not found.</exception>
        public static Bitmap Read(Stream stream)
        {
            using (var reader = new BinaryReader(stream, Encoding.ASCII))
            {
                if ((reader.ReadChar() == 'P' && reader.ReadChar() == '5') == false)
                    throw new BadImageFormatException("PGM Magic Number not found.");

                // Read onew whitespace character
                reader.ReadChar();

                // Get basic PGM format properties
                var parseBuffer = new StringBuilder();
                var pgmWidth = ReadInteger(reader, parseBuffer);
                var pgmHeight = ReadInteger(reader, parseBuffer);
                var grayscaleLevels = ReadInteger(reader, parseBuffer);
                var isTwoByteLevel = (grayscaleLevels > 255);

                // Create the bitmap and assign the 8bpp Indexed palette
                var bmp = new Bitmap(pgmWidth, pgmHeight, PixelFormat.Format8bppIndexed);
                bmp.Palette = GrayscalePalette;

                // Create the target lockbits
                var bitmapData = bmp.LockBits(new Rectangle(0, 0, pgmWidth, pgmHeight), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
                var rowLengthOffset = bitmapData.Stride - bitmapData.Width;
                var dataLength = bitmapData.Stride * bitmapData.Height;
                var pixelData = new byte[dataLength];

                var pixelDataIndex = 0;
                var currentPixelValue = (byte)0;

                for (int rowIndex = 0; rowIndex < pgmHeight; rowIndex++)
                {
                    for (int columnIndex = 0; columnIndex < pgmWidth; columnIndex++)
                    {
                        currentPixelValue = reader.ReadByte();
                        if (isTwoByteLevel)
                            currentPixelValue = (byte)(((double)((currentPixelValue << 8) + reader.ReadByte()) / grayscaleLevels) * 255.0);

                        pixelData[pixelDataIndex] = currentPixelValue;
                        pixelDataIndex++;
                    }

                    pixelDataIndex += rowLengthOffset;
                }

                // Use a fast copy mechanism to write the data to the bitmap
                System.Runtime.InteropServices.Marshal.Copy(pixelData, 0, bitmapData.Scan0, dataLength);

                // Release the write lock on the bits.
                bmp.UnlockBits(bitmapData);

                return bmp;
            }
        }
Example #17
0
 public static string ReadCString(BinaryReader rdr)
 {
     string ret = "";
     char c = rdr.ReadChar();
     while (c != '\0')
     {
         ret += c;
         c = rdr.ReadChar();
     }
     return "";
 }
Example #18
0
        static void Main(string[] args)
        {
            var values = new List<Value>();

            using (var strm = File.OpenRead(args[0]))
            {
                using (var rdr = new BinaryReader(strm))
                {
                    if (rdr.ReadChar() != 'S' || rdr.ReadChar() != 'T' || rdr.ReadChar() != 'R' || rdr.ReadChar() != 'M')
                        throw new Exception("Invalid header");
                    var tableCount = rdr.ReadInt32();
                    var valueCount = rdr.ReadInt32();
                    var charCount = rdr.ReadInt32();
                    //ulong sig = rdr.ReadUInt64();

                    strm.Seek(-charCount, SeekOrigin.End);

                    var chars = rdr.ReadBytes(charCount);

                    strm.Seek(24 + tableCount * TABLE_SIZE, SeekOrigin.Begin);

                    for (var i = 0; i < valueCount; i++)
                    {
                        var strOff = rdr.ReadInt32();
                        //int unused1 = rdr.ReadInt32();
                        //int unused2 = rdr.ReadInt32();
                        //int unused3 = rdr.ReadInt32();
                        var rva = rdr.ReadInt64();
                        values.Add(new Value(FromByteArray(chars, strOff), (ulong)rva));
                    }

                    values.Sort((a, b) => Comparer<string>.Default.Compare(a.Key, b.Key));

                    Console.WriteLine($"We loaded {values.Count} symbols!");
                }
            }

            using (var strm = File.OpenWrite("symbol_map.txt"))
            {
                using (var wtr = new StreamWriter(strm))
                {
                    for (var i = 0; i < values.Count; i++)
                    {
                        var value = values[i];
                        wtr.WriteLine($"0x{value.RVA:X} {value.Key}");
                    }
                    wtr.Flush();
                }
            }

            Console.ReadKey();
            Console.WriteLine("Done");
        }
Example #19
0
 protected override void OnSetData(BinaryReader reader)
 {
     this.Data.CommandId = reader.ReadInt32();
     this.Data.Text = reader.ReadString();
     this.Data.TransactTime = new DateTime(reader.ReadInt64());
     this.Data.CxlRejReason = reader.ReadInt32();
     this.Data.CxlRejResponseTo = reader.ReadChar();
     this.Data.OrderID = reader.ReadString();
     this.Data.OrdStatus = reader.ReadChar();
     this.Data.OrigClOrdID = reader.ReadString();
     this.Data.ClOrdID = reader.ReadString();
 }
Example #20
0
        public override void Deserialise(Stream xiInStream, int xiLength)
        {
            BinaryReader lReader = new BinaryReader(xiInStream);
              string lName = "";
              char lChar = lReader.ReadChar();
              while (lChar != 0)
              {
            lName += lChar;
            lChar = lReader.ReadChar();
              }

              mName = lName;
              return;
        }
Example #21
0
        public static PgmImg ReadPgmImg(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(fs, Encoding.ASCII))
                {
                    if (reader.ReadChar() == 'P' && reader.ReadChar() == '5')
                    {
                        reader.ReadChar();
                        int width = 0;
                        int height = 0;
                        int level = 0;
                        bool two = false;

                        width = ReadNumber(reader);
                        height = ReadNumber(reader);
                        level = ReadNumber(reader);
                        two = (level > 255);

                        var mat = new PgmImg(width, height);

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                byte v;
                                if (two)
                                {
                                    v = (byte)(((double)((reader.ReadByte() << 8) + reader.ReadByte()) / level) * 255.0);
                                }
                                else
                                {
                                    v = reader.ReadByte();
                                }

                                mat[j, i] = v;

                            }
                        }

                        return mat;
                    }
                    else
                    {
                        throw new InvalidOperationException("Is not a PGM file");
                    }

                }
            }
        }
        public string readStringTillZero(BinaryReader reader)
        {
            char[] work = new char[MAX_LENGTH];

            int i = 0;

            char c = reader.ReadChar();
            while (c != Convert.ToChar(0x00))
            {
                work[i++] = c;
                c = reader.ReadChar();
            }
            return new string(work, 0, i);

        }
Example #23
0
 public string ReadCString(BinaryReader br)
 {
     var offset = br.ReadUInt32();
     var oldPos = br.BaseStream.Position;
     br.BaseStream.Seek(offset, SeekOrigin.Begin);
     StringBuilder sb = new StringBuilder();
     char c = br.ReadChar();
     while (c!=0)
     {
         sb.Append(c);
         c = br.ReadChar();
     }
     br.BaseStream.Seek(oldPos, SeekOrigin.Begin);
     return sb.ToString();
 }
Example #24
0
        public void createTree(long[] array) {
            byte[] buffer = new byte[8];
            using (MemoryStream memory = new MemoryStream(buffer, true)) {
                for (int i = 0; i < array.Length; i++) {
                    using (BinaryWriter writer = new BinaryWriter(memory)) {
                        writer.Write(array[i]);
                    }

                    memory.Position = 0;
                    using (BinaryReader reader = new BinaryReader(memory)) {
                        while (buffer[memory.Position] == 0 && buffer[memory.Position + 1] == 0) {
                            reader.ReadChar();
                        }

                        allocateInTree(reader.ReadBytes((int) memory.Length - (int) memory.Position), root, buffer[i]);
                    }
                }
            }
//            ByteBuffer bb = ByteBuffer.allocate(8);
//        for (long item: array) {
//
//            bb.putLong(item);
//            bb.flip();
//
//            while (bb.array()[bb.position()] == 0 && bb.array()[bb.position()+1] == 0) {
//                bb.getChar();
//            }
//
//            allocateInTree(bb, root, item);
//            bb.clear();
//        }
    }
Example #25
0
            public static void Load()
            {
                var local = GetData("UFSJ.S.uscx");
                try
                {
                    using (var i = new BinaryReader(File.OpenRead(local)))
                    {
                        if (i.ReadChar() == 'U')
                        {
                            OnTopMost = i.ReadBoolean(); //OnTopMost
                            SilentProgress = i.ReadBoolean(); //SilentProgress
                            ShowSummary = i.ReadBoolean(); //ShowSummary
                            AssociateExt = i.ReadBoolean(); //AssociateExt
                            StartHide = i.ReadBoolean(); //StartHide
                            ShellMenus = i.ReadBoolean(); //ShellMenus
                            SettingMode = i.ReadInt16(); //SettingMode
                            Theme = i.ReadString(); //ColorScheme
                            Language = i.ReadString(); //Language
                            Formats = i.ReadString(); //Formats
                            Position = new Point(i.ReadInt32(), i.ReadInt32());
                        }
                    }
                }
                catch (Exception)
                {
                    SaveDefault();
                    Load();
                }

            }
Example #26
0
        private void ValidateDisposedExceptions(BinaryReader binaryReader)
        {
            byte[] byteBuffer = new byte[10];
            char[] charBuffer = new char[10];

            Assert.Throws<ObjectDisposedException>(() => binaryReader.PeekChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(byteBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(charBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBoolean());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBytes(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChars(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDecimal());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDouble());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt64());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSingle());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadString());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt64());
        }
Example #27
0
 private void ReadName(BinaryReader br)
 {
     StringBuilder sb = new StringBuilder();
     char c;
     while ((c = br.ReadChar()) > 0) sb.Append(c);
     _name = sb.ToString();
 }
        public override void FromStream(Stream stream)
        {
            base.FromStream(stream);

            long endOffset = (stream.Position + Header.Size + 1) & ~0x1;

            BinaryReader reader = new BinaryReader(stream);

            uint symbolCount = NativeUtils.SwapEndian(reader.ReadUInt32());

            SymbolsOffsets = new SymbolOffset[symbolCount];

            for (uint i = 0; i < symbolCount; ++i)
            {
                SymbolsOffsets[i].Offset = reader.ReadUInt32();
            }

            StringBuilder sb = new StringBuilder(1024);
            for (uint i = 0; i < symbolCount; ++i)
            {
                char c;
                while ((c = reader.ReadChar()) != 0)
                {
                    sb.Append(c);
                }

                SymbolsOffsets[i].Name = sb.ToString();
                sb.Clear();
            }

            stream.Seek(endOffset, SeekOrigin.Begin);
        }
        /// <summary>
        /// Creates a new instance of the DirectoryInfo struct and
        /// reads the information from the VPK BinaryReader.
        /// </summary>
        /// <param name="VPKReader">Stream to read directory information from.</param>
        internal DirectoryInfo(BinaryReader VPKReader)
        {
            // The stream is located at the end of the file, minus the size of the struct.
            VPKReader.BaseStream.Seek(-9, SeekOrigin.End);

            FileCount = VPKReader.ReadInt32();
            DirectoryOffset = (UInt32)VPKReader.ReadInt32();
            char type = VPKReader.ReadChar();

            switch (type)
            {
                case (char)DirectoryInfoType.PATHS_ONLY:
                    Type = DirectoryInfoType.PATHS_ONLY;
                    break;

                case (char)DirectoryInfoType.PATHS_AND_FILES:
                    Type = DirectoryInfoType.PATHS_AND_FILES;
                    break;

                default:
                    // Invalid, but Type isn't really used so we'll silenty ignore it.
                    Type = DirectoryInfoType.PATHS_AND_FILES;
                    break;
            }
        }
Example #30
0
 public static void ReadFrom(BinaryReader reader, FIXGroup group)
 {
     int num = reader.ReadInt32();
     for (int index = 0; index < num; ++index)
     {
         int tag = reader.ReadInt32();
         FIXType fixType = EFIXFieldTypes.GetFIXType(tag);
         switch (fixType)
         {
             case FIXType.Bool:
                 group.AddBoolField(tag, reader.ReadBoolean());
                 break;
             case FIXType.Int:
                 group.AddIntField(tag, reader.ReadInt32());
                 break;
             case FIXType.Double:
                 group.AddDoubleField(tag, reader.ReadDouble());
                 break;
             case FIXType.Char:
                 group.AddCharField(tag, reader.ReadChar());
                 break;
             case FIXType.String:
                 group.AddStringField(tag, reader.ReadString());
                 break;
             case FIXType.DateTime:
                 group.AddDateTimeField(tag, new DateTime(reader.ReadInt64()));
                 break;
             default:
                 throw new ArgumentException("" + fixType.ToString());
         }
     }
 }