event = XMLStreamConstants.END_ENTITY; return event;
event = END_ENTITY; return extendedEventTypes ? event : next();
  public int next()    throws XMLStreamException  {    if (lookahead)      {        lookahead = false;        return event;      }    if (event == XMLStreamConstants.END_ELEMENT)      {        // Pop namespace context        if (namespaceAware && !namespaces.isEmpty())          namespaces.removeFirst();        // Pop base context        if (baseAware && !bases.isEmpty())          bases.removeFirst();      }    if (!startEntityStack.isEmpty())      {        String entityName = (String) startEntityStack.removeFirst();        buf.setLength(0);        buf.append(entityName);        event = XMLStreamConstants.START_ENTITY;        return event;      }    else if (!endEntityStack.isEmpty())      {        String entityName = (String) endEntityStack.removeFirst();        buf.setLength(0);        buf.append(entityName);        event = XMLStreamConstants.END_ENTITY;        return event;      }    try      {        if (!input.initialized)            input.init();        switch (state)          {          case CONTENT:            if (tryRead(TEST_END_ELEMENT))              {                readEndElement();                if (stack.isEmpty())                  state = MISC;                event = XMLStreamConstants.END_ELEMENT;              }            else if (tryRead(TEST_COMMENT))              {                readComment(false);                event = XMLStreamConstants.COMMENT;              }            else if (tryRead(TEST_PI))              {                readPI(false);                event = XMLStreamConstants.PROCESSING_INSTRUCTION;              }            else if (tryRead(TEST_CDATA))              {                readCDSect();                event = XMLStreamConstants.CDATA;              }            else if (tryRead(TEST_START_ELEMENT))              {                state = readStartElement();                event = XMLStreamConstants.START_ELEMENT;              }            else              {                // Check for character reference or predefined entity                mark(8);                int c = readCh();                if (c == 0x26) // '&'                  {                    c = readCh();                    if (c == 0x23) // '#'                      {                        reset();                        event = readCharData(null);                      }                    else                      {                        // entity reference                        reset();                        readCh(); // &                        readReference();                        String ref = buf.toString();                        String text = (String) PREDEFINED_ENTITIES.get(ref);                        if (text != null)                          {                            event = readCharData(text);                          }                        else if (replaceERefs && !isUnparsedEntity(ref))                          {                            // this will report a start-entity event                            boolean external = false;                            if (doctype != null)                              {                                Object entity = doctype.getEntity(ref);                                if (entity instanceof ExternalIds)                                  external = true;                              }                            expandEntity(ref, false, external);                            event = next();                          }                        else                          {                            event = XMLStreamConstants.ENTITY_REFERENCE;                          }                      }                  }                else                  {                    reset();                    event = readCharData(null);                    if (validating && doctype != null)                      validatePCData(buf.toString());                  }              }            break;          case EMPTY_ELEMENT:            String elementName = (String) stack.removeLast();            buf.setLength(0);            buf.append(elementName);            state = stack.isEmpty() ? MISC : CONTENT;            event = XMLStreamConstants.END_ELEMENT;            if (validating && doctype != null)              endElementValidationHook();            break;          case INIT: // XMLDecl?            if (tryRead(TEST_XML_DECL))              readXMLDecl();            input.finalizeEncoding();            event = XMLStreamConstants.START_DOCUMENT;            state = PROLOG;            break;          case PROLOG: // Misc* (doctypedecl Misc*)?            skipWhitespace();            if (doctype == null && tryRead(TEST_DOCTYPE_DECL))              {                readDoctypeDecl();                event = XMLStreamConstants.DTD;              }            else if (tryRead(TEST_COMMENT))              {                readComment(false);                event = XMLStreamConstants.COMMENT;              }            else if (tryRead(TEST_PI))              {                readPI(false);                event = XMLStreamConstants.PROCESSING_INSTRUCTION;              }            else if (tryRead(TEST_START_ELEMENT))              {                state = readStartElement();                event = XMLStreamConstants.START_ELEMENT;              }            else              {                int c = readCh();                error("no root element: U+" + Integer.toHexString(c));              }            break;          case MISC: // Comment | PI | S            skipWhitespace();            if (tryRead(TEST_COMMENT))              {                readComment(false);                event = XMLStreamConstants.COMMENT;              }            else if (tryRead(TEST_PI))              {                readPI(false);                event = XMLStreamConstants.PROCESSING_INSTRUCTION;              }            else              {                if (event == XMLStreamConstants.END_DOCUMENT)                  throw new NoSuchElementException();                int c = readCh();                if (c != -1)                  error("Only comments and PIs may appear after " +                        "the root element");                event = XMLStreamConstants.END_DOCUMENT;              }            break;          default:            event = -1;          }        return event;      }    catch (IOException e)      {        XMLStreamException e2 = new XMLStreamException();        e2.initCause(e);        throw e2;      }  }