Code example for ByteArrayBuffer

Methods: buffer, byteAt, length, setLength

0
    } 
     
    private int lineFromLineBuffer(final CharArrayBuffer charbuffer) 
            throws IOException { 
        // discard LF if found 
        int l = this.linebuffer.length(); 
        if (l > 0) {
            if (this.linebuffer.byteAt(l - 1) == HTTP.LF) {
                l--;
                this.linebuffer.setLength(l);
            } 
            // discard CR if found 
            if (l > 0) {
                if (this.linebuffer.byteAt(l - 1) == HTTP.CR) {
                    l--;
                    this.linebuffer.setLength(l);
                } 
            } 
        } 
        l = this.linebuffer.length(); 
        if (this.ascii) {
            charbuffer.append(this.linebuffer, 0, l);
        } else { 
            // This is VERY memory inefficient, BUT since non-ASCII charsets are  
            // NOT meant to be used anyway, there's no point optimizing it 
            String s = new String(this.linebuffer.buffer(), 0, l, this.charset);
            charbuffer.append(s);
        } 
        return l;
    }