cache = new char[capacity];
char[] chars = str.toCharArray(); int available = cache.length - pos; int toWrite = chars.length < available ? chars.length : available; System.arraycopy(chars, 0, cache, pos, toWrite); pos += toWrite;
if (pos < cache.length - 1) { cache[pos] = c; pos++; }
pos = 0;
return pos;
return new String(cache, 0, pos);