Exemplo n.º 1
0
        /// <summary>
        /// Loads ArrayTrie from an arbitrary <see cref="Stream"/>.
        /// <paramref name="sourceStream"/> is closed and
        /// disposed once this method completes.
        /// </summary>
        /// <param name="sourceStream">
        /// A <see cref="Stream"/> containing the model.
        /// </param>
        /// <param name="numberOfElementsInChunk">
        /// Number of elements (2 int32) in read buffer. 
        /// Default is 2048 (16K buffer size)</param>
        public void Load(Stream sourceStream, int numberOfElementsInChunk = 2048)
        {
            const int int32Size = sizeof(int);
            const int elementSize = int32Size * 2;
            var fileSizeInBytes = sourceStream.Length;
            var numberOfElements = fileSizeInBytes / elementSize;
#if NO_SUPPORT_VERY_BIG_OBJECT
            array = new VarBigArray<sunit_t>(numberOfElements);
#else
            array = new sunit_t[numberOfElements];
#endif
            using (var sr = new StreamReader(sourceStream))
            using (var br = new BinaryReader(sr.BaseStream))
            {
                var buffersize = elementSize * numberOfElementsInChunk;
                var buffer = new byte[elementSize * numberOfElementsInChunk];
                var index = 0;
                for (long j = 0; j <= numberOfElements / numberOfElementsInChunk; j++)
                {
                    var numberOfReadBytes = br.Read(buffer, 0, buffersize);
                    if (numberOfReadBytes == buffersize)
                    {
                        for (int i = 0; i < numberOfElementsInChunk; i++, index++)
                        {
                            var base1 = BitConverter.ToInt32(buffer, elementSize * i);
                            var check = BitConverter.ToInt32(buffer, (elementSize * i) + int32Size);
                            array[index] = new sunit_t(base1, check);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < numberOfReadBytes / elementSize; i++)
                        {
                            var base1 = BitConverter.ToInt32(buffer, elementSize * i);
                            var check = BitConverter.ToInt32(buffer, (elementSize * i) + int32Size);
                            array[index++] = new sunit_t(base1, check);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Load(String fileName)
        {
            StreamReader sr = new StreamReader(fileName);
            BinaryReader br = new BinaryReader(sr.BaseStream);
            FileInfo fi = new FileInfo(fileName);

            int i = 0;
#if NO_SUPPORT_VERY_BIG_OBJECT
            array = new VarBigArray<sunit_t>(fi.Length / 8);
#else
            array = new sunit_t[fi.Length / 8];
#endif
            for (i = 0; i < array.LongLength; i++)
            {
                int base1 = br.ReadInt32();
                int check = br.ReadInt32();
                array[i] = new sunit_t(base1, check);
            }

            br.Close();
        }