if (dataString.trim().length() == 0) { return readChunkLength(); }
    private int readChunkLength() throws IOException {                ByteArrayOutputStream baos = new ByteArrayOutputStream();        int state = 0;         while (state != -1) {            int b = mySource.read();            if (b == -1) {                 throw new IOException("Chunked stream ended unexpectedly");            }            switch (state) {                case 0:                     switch (b) {                        case '\r':                            state = 1;                            break;                        case '\"':                            state = 2;                        default:                            baos.write(b);                    }                    break;                case 1:                    if (b == '\n') {                        state = -1;                    } else {                        throw new IOException("Protocol violation: Unexpected single newline character in chunk size");                    }                    break;                case 2:                    switch (b) {                        case '\\':                            b = mySource.read();                            baos.write(b);                            break;                        case '\"':                            state = 0;                        default:                            baos.write(b);                    }                    break;                default: throw new IOException("Assertion failed while reading chunk length");            }        }        String dataString = new String(baos.toByteArray());        int separator = dataString.indexOf(';');        dataString = (separator > 0) ? dataString.substring(0, separator).trim() : dataString.trim();        int result;        try {            result = Integer.parseInt(dataString.trim(), 16);        } catch (NumberFormatException e) {            throw new IOException ("Bad chunk size: " + dataString);        }        return result;    }