Code example for CharArrayBuffer

Methods: clear, indexOf, isEmpty, length, substringTrimmed

0
     */ 
    private int getChunkSize() throws IOException { 
        final int st = this.state;
        switch (st) {
        case CHUNK_CRLF:
            this.buffer.clear();
            final int bytesRead1 = this.in.readLine(this.buffer);
            if (bytesRead1 == -1) {
                return 0; 
            } 
            if (!this.buffer.isEmpty()) {
                throw new MalformedChunkCodingException(
                    "Unexpected content at the end of chunk"); 
            } 
            state = CHUNK_LEN;
            //$FALL-THROUGH$ 
        case CHUNK_LEN:
            this.buffer.clear();
            final int bytesRead2 = this.in.readLine(this.buffer);
            if (bytesRead2 == -1) {
                return 0; 
            } 
            int separator = this.buffer.indexOf(';');
            if (separator < 0) {
                separator = this.buffer.length();
            } 
            try { 
                return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
            } catch (final NumberFormatException e) {
                throw new MalformedChunkCodingException("Bad chunk header");
            } 
        default: 
            throw new IllegalStateException("Inconsistent codec state");