int ch = 0; StringBuffer sb = new StringBuffer(); while(true) { int r = mySource.read(); if (r < 0) { return 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream(); int state = 0; while (state != -1) { int b = mySource.read(); if (b == -1) { throw new IOException("Chunked stream ended unexpectedly");
    private int readChunkLength() throws IOException {        int ch = 0;        StringBuffer sb = new StringBuffer();        while(true) {            int r = mySource.read();            if (r < 0) {                return 0;            }            ch = (char) r;            if (ch == '\r') {                continue;            }            if (ch == '\n' || ch == '\r') {                if (sb.length() == 0) {                    continue;                }                break;            }            sb.append((char) ch);        }        return Integer.parseInt(sb.toString(), 16);    }