Lucene.Net.Analysis.Tokenattributes.CharTermAttribute.ResizeBuffer C# (CSharp) Method

ResizeBuffer() public method

public ResizeBuffer ( int newSize ) : char[]
newSize int
return char[]
        public char[] ResizeBuffer(int newSize)
        {
            if (TermBuffer.Length < newSize)
            {
                // Not big enough; create a new array with slight
                // over allocation and preserve content
                char[] newCharBuffer = new char[ArrayUtil.Oversize(newSize, RamUsageEstimator.NUM_BYTES_CHAR)];
                Array.Copy(TermBuffer, 0, newCharBuffer, 0, TermBuffer.Length);
                TermBuffer = newCharBuffer;
            }
            return TermBuffer;
        }

Usage Example

 public virtual void TestResize()
 {
     CharTermAttribute t = new CharTermAttribute();
     char[] content = "hello".ToCharArray();
     t.CopyBuffer(content, 0, content.Length);
     for (int i = 0; i < 2000; i++)
     {
         t.ResizeBuffer(i);
         Assert.IsTrue(i <= t.Buffer().Length);
         Assert.AreEqual("hello", t.ToString());
     }
 }
All Usage Examples Of Lucene.Net.Analysis.Tokenattributes.CharTermAttribute::ResizeBuffer