コード例 #1
0
ファイル: PagedBytes.cs プロジェクト: ywscr/lucenenet
            public override object Clone()
            {
                PagedBytesDataInput clone = outerInstance.GetDataInput();

                clone.SetPosition(GetPosition());
                return(clone);
            }
コード例 #2
0
        public virtual void TestDataInputOutput2()
        {
            Random random = Random;

            for (int iter = 0; iter < 5 * RandomMultiplier; iter++)
            {
                int        blockBits = TestUtil.NextInt32(random, 1, 20);
                int        blockSize = 1 << blockBits;
                PagedBytes p         = new PagedBytes(blockBits);
                DataOutput @out      = p.GetDataOutput();
                int        numBytes  = LuceneTestCase.Random.Next(10000000);

                byte[] answer = new byte[numBytes];
                LuceneTestCase.Random.NextBytes(answer);
                int written = 0;
                while (written < numBytes)
                {
                    if (LuceneTestCase.Random.Next(10) == 7)
                    {
                        @out.WriteByte(answer[written++]);
                    }
                    else
                    {
                        int chunk = Math.Min(LuceneTestCase.Random.Next(1000), numBytes - written);
                        @out.WriteBytes(answer, written, chunk);
                        written += chunk;
                    }
                }

                PagedBytes.Reader reader = p.Freeze(random.NextBoolean());

                DataInput @in = p.GetDataInput();

                byte[] verify = new byte[numBytes];
                int    read   = 0;
                while (read < numBytes)
                {
                    if (LuceneTestCase.Random.Next(10) == 7)
                    {
                        verify[read++] = @in.ReadByte();
                    }
                    else
                    {
                        int chunk = Math.Min(LuceneTestCase.Random.Next(1000), numBytes - read);
                        @in.ReadBytes(verify, read, chunk);
                        read += chunk;
                    }
                }
                Assert.IsTrue(Arrays.Equals(answer, verify));

                BytesRef slice = new BytesRef();
                for (int iter2 = 0; iter2 < 100; iter2++)
                {
                    int pos = random.Next(numBytes - 1);
                    int len = random.Next(Math.Min(blockSize + 1, numBytes - pos));
                    reader.FillSlice(slice, pos, len);
                    for (int byteUpto = 0; byteUpto < len; byteUpto++)
                    {
                        Assert.AreEqual(answer[pos + byteUpto], (byte)slice.Bytes[slice.Offset + byteUpto]);
                    }
                }
            }
        }