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;
}
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()); } }