code: private int readChunkLength()
      throws IOException
    {
      int length = 0;
      int ch;
  
      ReadStream is = _next;
  
      // skip whitespace
      for (ch = is.read();
           ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
           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 != '\r' && ch != '\n'; ch = is.read()) {
        if ('0' <= ch && ch <= '9')
          length = 16 * length + ch - '0';
        else if ('a' <= ch && ch <= 'f')
          length = 16 * length + ch - 'a' + 10;
        else if ('A' <= ch && ch <= 'F')
          length = 16 * length + ch - 'A' + 10;
        else if (ch == ' ' || ch == '\t') {
          //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 != '\r' && ch1 != '\n';
               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 == '\r')
        ch = is.read();
  
      return length;
    }
docs: Reads the next chunk length from the input stream.