private int readChunkLength ( ) throws IOException { int length = 0 ; int ch ; ReadStream is = _next ; // skip whitespace for ( ch = is . read ( ) ; ch == ' ' || ch == ' ' || ch == ' ' || ch == ' ' ; ch = is . read ( ) ) { } // XXX: This doesn't properly handle the case when when the browser // sends headers at the end of the data. See the HTTP/1.1 spec. for ( ; ch > 0 && ch != ' ' && ch != ' ' ; ch = is . read ( ) ) { if ( ' ' <= ch && ch <= ' ' ) length = 16 * length + ch - ' ' ; else if ( ' ' <= ch && ch <= ' ' ) length = 16 * length + ch - ' ' + 10 ; else if ( ' ' <= ch && ch <= ' ' ) length = 16 * length + ch - ' ' + 10 ; else if ( ch == ' ' || ch == ' ' ) { //if (dbg.canWrite()) // dbg.println("unexpected chunk whitespace."); } else { StringBuilder sb = new StringBuilder ( ) ; sb . append ( ( char ) ch ) ; for ( int ch1 = is . read ( ) ; ch1 >= 0 && ch1 != ' ' && ch1 != ' ' ; ch1 = is . read ( ) ) { sb . append ( ( char ) ch1 ) ; } throw new IOException ( "HTTP/1.1 protocol error: bad chunk at" + " '" + sb + "'" + " 0x" + Integer . toHexString ( ch ) + " length=" + length ) ; } } if ( ch == ' ' ) ch = is . read ( ) ; return length ; }
Reads the next chunk length from the input stream .