示例#1
0
        private void  AssertSameStreams(System.String msg, IndexInput expected, IndexInput test)
        {
            Assert.IsNotNull(expected, msg + " null expected");
            Assert.IsNotNull(test, msg + " null test");
            Assert.AreEqual(expected.Length(null), test.Length(null), msg + " length");
            Assert.AreEqual(expected.FilePointer(null), test.FilePointer(null), msg + " position");

            byte[] expectedBuffer = new byte[512];
            byte[] testBuffer     = new byte[expectedBuffer.Length];

            long remainder = expected.Length(null) - expected.FilePointer(null);

            while (remainder > 0)
            {
                int readLen = (int)System.Math.Min(remainder, expectedBuffer.Length);
                expected.ReadBytes(expectedBuffer, 0, readLen, null);
                test.ReadBytes(testBuffer, 0, readLen, null);
                AssertEqualArrays(msg + ", remainder " + remainder, expectedBuffer, testBuffer, 0, readLen);
                remainder -= readLen;
            }
        }
示例#2
0
        public virtual void  TestRandomAccessClones()
        {
            SetUp_2();
            CompoundFileReader cr = new CompoundFileReader(dir, "f.comp", null);

            // Open two files
            IndexInput e1 = cr.OpenInput("f11", null);
            IndexInput e2 = cr.OpenInput("f3", null);

            IndexInput a1 = (IndexInput)e1.Clone(null);
            IndexInput a2 = (IndexInput)e2.Clone(null);

            // Seek the first pair
            e1.Seek(100, null);
            a1.Seek(100, null);
            Assert.AreEqual(100, e1.FilePointer(null));
            Assert.AreEqual(100, a1.FilePointer(null));
            byte be1 = e1.ReadByte(null);
            byte ba1 = a1.ReadByte(null);

            Assert.AreEqual(be1, ba1);

            // Now seek the second pair
            e2.Seek(1027, null);
            a2.Seek(1027, null);
            Assert.AreEqual(1027, e2.FilePointer(null));
            Assert.AreEqual(1027, a2.FilePointer(null));
            byte be2 = e2.ReadByte(null);
            byte ba2 = a2.ReadByte(null);

            Assert.AreEqual(be2, ba2);

            // Now make sure the first one didn't move
            Assert.AreEqual(101, e1.FilePointer(null));
            Assert.AreEqual(101, a1.FilePointer(null));
            be1 = e1.ReadByte(null);
            ba1 = a1.ReadByte(null);
            Assert.AreEqual(be1, ba1);

            // Now more the first one again, past the buffer length
            e1.Seek(1910, null);
            a1.Seek(1910, null);
            Assert.AreEqual(1910, e1.FilePointer(null));
            Assert.AreEqual(1910, a1.FilePointer(null));
            be1 = e1.ReadByte(null);
            ba1 = a1.ReadByte(null);
            Assert.AreEqual(be1, ba1);

            // Now make sure the second set didn't move
            Assert.AreEqual(1028, e2.FilePointer(null));
            Assert.AreEqual(1028, a2.FilePointer(null));
            be2 = e2.ReadByte(null);
            ba2 = a2.ReadByte(null);
            Assert.AreEqual(be2, ba2);

            // Move the second set back, again cross the buffer size
            e2.Seek(17, null);
            a2.Seek(17, null);
            Assert.AreEqual(17, e2.FilePointer(null));
            Assert.AreEqual(17, a2.FilePointer(null));
            be2 = e2.ReadByte(null);
            ba2 = a2.ReadByte(null);
            Assert.AreEqual(be2, ba2);

            // Finally, make sure the first set didn't move
            // Now make sure the first one didn't move
            Assert.AreEqual(1911, e1.FilePointer(null));
            Assert.AreEqual(1911, a1.FilePointer(null));
            be1 = e1.ReadByte(null);
            ba1 = a1.ReadByte(null);
            Assert.AreEqual(be1, ba1);

            e1.Close();
            e2.Close();
            a1.Close();
            a2.Close();
            cr.Close();
        }