Пример #1
0
        public static void Tests()
        {
            string testOrig = "text.orig";

            Random r = new Random(23);

            for (int j = 0; j < 10; j++)
            {
                for (int fileSize = 1023; fileSize <= 1025; fileSize++)
                {
                    CreateDataFile(testOrig, fileSize);
                    byte[] origData = File.ReadAllBytes(testOrig);

                    for (int bufferSize = 16; bufferSize < 300; bufferSize += 24)
                    {
                        FileStream         testData = File.OpenRead(testOrig);
                        PinnedStreamReader reader   = new PinnedStreamReader(testData, bufferSize);

                        // Try reading back in various seek positions.
                        for (int i = 0; i < 100; i++)
                        {
                            int position = r.Next(0, origData.Length);
                            int size     = r.Next(0, bufferSize) + 1;

                            reader.Goto((StreamLabel)position);
                            Compare(reader, origData, position, size);
                        }
                        reader.Close();
                    }
                }
                Console.WriteLine("Finished Round " + j);
            }
        }
Пример #2
0
        private static void Compare(PinnedStreamReader reader, byte[] buffer, int offset, int chunkSize)
        {
            compareCount++;
            if (compareCount == -1)
            {
                Debugger.Break();
            }

            for (int pos = offset; pos < buffer.Length; pos += chunkSize)
            {
                if (pos + chunkSize > buffer.Length)
                {
                    chunkSize = buffer.Length - pos;
                }
                CompareBuffer(reader.GetPointer(chunkSize), buffer, pos, chunkSize);
                reader.Skip(chunkSize);
            }
        }
Пример #3
0
        public PinnedStreamReader Clone()
        {
            PinnedStreamReader ret = new PinnedStreamReader(inputStream, bytes.Length - align);

            return(ret);
        }
Пример #4
0
        private static void Compare(PinnedStreamReader reader, byte[] buffer, int offset, int chunkSize)
        {
            compareCount++;
            if (compareCount == -1)
                Debugger.Break();

            for (int pos = offset; pos < buffer.Length; pos += chunkSize)
            {
                if (pos + chunkSize > buffer.Length)
                    chunkSize = buffer.Length - pos;
                CompareBuffer(reader.GetPointer(chunkSize), buffer, pos, chunkSize);
                reader.Skip(chunkSize);
            }
        }
Пример #5
0
        public static void Tests()
        {
            string testOrig = "text.orig";

            Random r = new Random(23);

            for (int j = 0; j < 10; j++)
            {
                for (int fileSize = 1023; fileSize <= 1025; fileSize++)
                {
                    CreateDataFile(testOrig, fileSize);
                    byte[] origData = File.ReadAllBytes(testOrig);

                    for (int bufferSize = 16; bufferSize < 300; bufferSize += 24)
                    {
                        FileStream testData = File.OpenRead(testOrig);
                        PinnedStreamReader reader = new PinnedStreamReader(testData, bufferSize);

                        // Try reading back in various seek positions. 
                        for (int i = 0; i < 100; i++)
                        {
                            int position = r.Next(0, origData.Length);
                            int size = r.Next(0, bufferSize) + 1;

                            reader.Goto((StreamLabel)position);
                            Compare(reader, origData, position, size);
                        }
                        reader.Close();
                    }
                }
                Console.WriteLine("Finished Round " + j);
            }
        }
Пример #6
0
 public PinnedStreamReader Clone()
 {
     PinnedStreamReader ret = new PinnedStreamReader(inputStream, bytes.Length - align);
     return ret;
 }