1 22 23 package org.gjt.sp.util; 24 25 import javax.swing.text.Segment ; 26 27 30 public class SegmentBuffer extends Segment 31 { 32 public SegmentBuffer(int capacity) 34 { 35 ensureCapacity(capacity); 36 } 38 public void append(char ch) 40 { 41 ensureCapacity(count + 1); 42 array[offset + count] = ch; 43 count++; 44 } 46 public void append(char[] text, int off, int len) 48 { 49 ensureCapacity(count + len); 50 System.arraycopy(text,off,array,count,len); 51 count += len; 52 } 54 56 private void ensureCapacity(int capacity) 58 { 59 if(array == null) 60 array = new char[capacity]; 61 else if(capacity >= array.length) 62 { 63 char[] arrayN = new char[capacity * 2]; 64 System.arraycopy(array,0,arrayN,0,count); 65 array = arrayN; 66 } 67 } 69 } 71 | Popular Tags |