class CharCache {
    private char[] cache;
    private int pos;

    public CharCache(int capacity) {
        cache = new char[capacity];
    }

    public void append(String str) {<FILL_FUNCTION_BODY>}

    public String toString() {
        return new String(cache, 0, pos);
    }

    public void clear() {
        pos = 0;
    }

    public void append(char c) {
        if (pos < cache.length - 1) {
            cache[pos] = c;
            pos++;
        }
    }

    public int length() {
        return pos;
    }
}

        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;
    
<no_super_class>