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

ByteArrayBuffer

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

Fields Summary
private byte[]
buffer
private int
len
Constructors Summary
public ByteArrayBuffer(int capacity)

        super();
        if (capacity < 0) {
            throw new IllegalArgumentException("Buffer capacity may not be negative");
        }
        this.buffer = new byte[capacity]; 
    
Methods Summary
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 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(int b)

        int newlen = this.len + 1;
        if (newlen > this.buffer.length) {
            expand(newlen);
        }
        this.buffer[this.len] = (byte)b;
        this.len = newlen;
    
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 oldlen = this.len;
        int newlen = oldlen + len;
        if (newlen > this.buffer.length) {
            expand(newlen);
        }
        for (int i1 = off, i2 = oldlen; i2 < newlen; i1++, i2++) {
            this.buffer[i2] = (byte) b[i1];
        }
        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 byte[]buffer()

        return this.buffer;
    
public intbyteAt(int i)

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

        return this.buffer.length;
    
public voidclear()

        this.len = 0;
    
private voidexpand(int newlen)

        byte newbuffer[] = new byte[Math.max(this.buffer.length << 1, newlen)];
        System.arraycopy(this.buffer, 0, newbuffer, 0, this.len);
        this.buffer = newbuffer;
    
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 byte[]toByteArray()

        byte[] b = new byte[this.len]; 
        if (this.len > 0) {
            System.arraycopy(this.buffer, 0, b, 0, this.len);
        }
        return b;