FileDocCategorySizeDatePackage
CharArrayBuffer.javaAPI DocAndroid 1.5 API7505Wed May 06 22:41:10 BST 2009org.apache.http.util

CharArrayBuffer

public final class CharArrayBuffer extends Object
A resizable char array.
author
Oleg Kalnichevski
version
$Revision: 496070 $
since
4.0

Fields Summary
private char[]
buffer
private int
len
Constructors Summary
public CharArrayBuffer(int capacity)

        super();
        if (capacity < 0) {
            throw new IllegalArgumentException("Buffer capacity may not be negative");
        }
        this.buffer = new char[capacity]; 
    
Methods Summary
public voidappend(java.lang.Object obj)

        append(String.valueOf(obj));
    
public voidappend(char[] b, int off, int len)

        if (b == null) {
            return;
        }
        if ((off < 0) || (off > b.length) || (len < 0) ||
                ((off + len) < 0) || ((off + len) > b.length)) {
            throw new IndexOutOfBoundsException();
        }
        if (len == 0) {
            return;
        }
        int newlen = this.len + len;
        if (newlen > this.buffer.length) {
            expand(newlen);
        }
        System.arraycopy(b, off, this.buffer, this.len, len);
        this.len = newlen;
    
public voidappend(java.lang.String str)

        if (str == null) {
            str = "null";
        }
        int strlen = str.length();
        int newlen = this.len + strlen;
        if (newlen > this.buffer.length) {
            expand(newlen);
        }
        str.getChars(0, strlen, this.buffer, this.len);
        this.len = newlen;
    
public voidappend(org.apache.http.util.CharArrayBuffer b, int off, int len)

        if (b == null) {
            return;
        }
        append(b.buffer, off, len);
    
public voidappend(org.apache.http.util.CharArrayBuffer b)

        if (b == null) {
            return;
        }
        append(b.buffer,0, b.len);
    
public voidappend(char ch)

        int newlen = this.len + 1;
        if (newlen > this.buffer.length) {
            expand(newlen);
        }
        this.buffer[this.len] = ch;
        this.len = newlen;
    
public voidappend(byte[] b, int off, int len)

        if (b == null) {
            return;
        }
        if ((off < 0) || (off > b.length) || (len < 0) ||
                ((off + len) < 0) || ((off + len) > b.length)) {
            throw new IndexOutOfBoundsException();
        }
        if (len == 0) {
            return;
        }
        int oldlen = this.len;
        int newlen = oldlen + len;
        if (newlen > this.buffer.length) {
            expand(newlen);
        }
        for (int i1 = off, i2 = oldlen; i2 < newlen; i1++, i2++) {
            int ch = b[i1]; 
            if (ch < 0) {
                ch = 256 + ch;
            }
            this.buffer[i2] = (char) ch;
        }
        this.len = newlen;
    
public voidappend(org.apache.http.util.ByteArrayBuffer b, int off, int len)

        if (b == null) {
            return;
        }
        append(b.buffer(), off, len);
    
public char[]buffer()

        return this.buffer;
    
public intcapacity()

        return this.buffer.length;
    
public charcharAt(int i)

        return this.buffer[i];
    
public voidclear()

        this.len = 0;
    
public voidensureCapacity(int required)

        int available = this.buffer.length - this.len;
        if (required > available) {
            expand(this.len + required);
        }
    
private voidexpand(int newlen)

        char newbuffer[] = new char[Math.max(this.buffer.length << 1, newlen)];
        System.arraycopy(this.buffer, 0, newbuffer, 0, this.len);
        this.buffer = newbuffer;
    
public intindexOf(int ch, int beginIndex, int endIndex)

        if (beginIndex < 0) {
            beginIndex = 0;
        }
        if (endIndex > this.len) {
            endIndex = this.len;
        }
        if (beginIndex > endIndex) {
            return -1;
        }
        for (int i = beginIndex; i < endIndex; i++) {
            if (this.buffer[i] == ch) {
                return i;
            }
        }
        return -1;
    
public intindexOf(int ch)

        return indexOf(ch, 0, this.len);
    
public booleanisEmpty()

        return this.len == 0; 
    
public booleanisFull()

        return this.len == this.buffer.length; 
    
public intlength()

        return this.len;
    
public voidsetLength(int len)

        if (len < 0 || len > this.buffer.length) {
            throw new IndexOutOfBoundsException();
        }
        this.len = len;
    
public java.lang.Stringsubstring(int beginIndex, int endIndex)

        if (beginIndex < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (endIndex > this.len) {
            throw new IndexOutOfBoundsException();
        }
        if (beginIndex > endIndex) {
            throw new IndexOutOfBoundsException();
        }
        return new String(this.buffer, beginIndex, endIndex - beginIndex);
    
public java.lang.StringsubstringTrimmed(int beginIndex, int endIndex)

        if (beginIndex < 0) {
            throw new IndexOutOfBoundsException();
        }
        if (endIndex > this.len) {
            throw new IndexOutOfBoundsException();
        }
        if (beginIndex > endIndex) {
            throw new IndexOutOfBoundsException();
        }
        while (beginIndex < endIndex && HTTP.isWhitespace(this.buffer[beginIndex])) {
            beginIndex++;
        }
        while (endIndex > beginIndex && HTTP.isWhitespace(this.buffer[endIndex - 1])) {
            endIndex--;
        }
        return new String(this.buffer, beginIndex, endIndex - beginIndex);
    
public char[]toCharArray()

        char[] b = new char[this.len]; 
        if (this.len > 0) {
            System.arraycopy(this.buffer, 0, b, 0, this.len);
        }
        return b;
    
public java.lang.StringtoString()

        return new String(this.buffer, 0, this.len);