{@inheritDoc}
@see org.jboss.staxmapper.XMLElementReader#readElement(org.jboss.staxmapper.XMLExtendedStreamReader, Object)
340365
@Override
    public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException {

        Map<PathAddress, ModelNode> operations = new LinkedHashMap<>();

        PathAddress subsystemAddress = PathAddress.pathAddress(InfinispanExtension.SUBSYSTEM_PATH);
        ModelNode subsystem = Util.createAddOperation(subsystemAddress);

        // command to add the subsystem
        operations.put(subsystemAddress, subsystem);

        while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
            Element element = Element.forName(reader.getLocalName());
            switch (element) {
                case CACHE_CONTAINER: {
                    parseContainer(reader, subsystemAddress, operations);
                    break;
                }
                default: {
                    throw ParseUtils.unexpectedElement(reader);
                }
            }
        }

        result.addAll(operations.values());
    }
366604
public void readXML(@WillClose InputStream in, File base) throws IOException, DocumentException {
        try {
            doReadXML(in, base);
        } finally {
            in.close();
        }
    }
139852
public void complete(Element e) throws KNXMLException
	{
		if (e.isEmptyElementTag())
			return;
		final int index = openElems.lastIndexOf(e.getName());
		if (index == -1)
			throw new KNXMLException("element tag not read before", e.getName(), line);
		String end = null;
		final StringBuffer content = new StringBuffer(50);
		while (canRead()) {
			// read text content
			final String s = read('<');
			final boolean current = openElems.peek().equals(e.getName());
			// if character data is for current element, append it
			if (current && s.length() > 0)
				content.append(References.replace(s, false));
			// read a possible end tag
			end = read('>');
			if (skipComment(end))
				;
			else if (current && readCDATASection(end, content))
				;
			else if (end.length() > 0 && end.charAt(0) == '/') {
				// actually, no white space is allowed between '/' and tag name
				// but there might be some between end of name and '>'
				final String tag = end.substring(1).trim();
				// got end tag?
				if (!tag.equals(openElems.peek()))
					throw new KNXMLException("element end tag does not match start tag",
						tag, line);
				openElems.pop();
				if (tag.equals(e.getName())) {
					e.setCharacterData(content.toString());
					pos = END_TAG;
					return;
				}
			}
			else if (end.length() > 0)
				// don't push empty element tags
				if (end.charAt(end.length() - 1) != '/') {
					final String tag = splitOnSpace(end);
					if (tag.length() > 0)
						openElems.push(tag);
				}
		}
		throw new KNXMLException("end of XML input with elements left open", end, line);
	}
523364
@Override
    protected XMLEvent internalNextEvent() throws XMLStreamException {
        // If there is an iterator to read from reset was called, use the iterator
        // until it runs out of events.
        if (this.bufferReader != null) {
            final XMLEvent event = this.bufferReader.next();

            // If nothing left in the iterator, remove the reference and fall through to direct
            // reading
            if (!this.bufferReader.hasNext()) {
                this.bufferReader = null;
            }

            return event;
        }

        // Get the next event from the underlying reader
        final XMLEvent event = this.getParent().nextEvent();

        // if buffering add the event
        if (this.eventLimit != 0) {
            this.eventBuffer.offer(event);

            // If limited buffer size and buffer is too big trim the buffer.
            if (this.eventLimit > 0 && this.eventBuffer.size() > this.eventLimit) {
                this.eventBuffer.poll();
            }
        }

        return event;
    }
650723
public static void skipElement(final XMLStreamReader reader) throws XMLStreamException, IOException {
        if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) {
            return;
        }
        final String namespace = reader.getNamespaceURI();
        final String name = reader.getLocalName();
        for (;;) {
            switch (reader.nextTag()) {
            case XMLStreamConstants.START_ELEMENT:
                // call ourselves recursively if we encounter START_ELEMENT
                skipElement(reader);
                break;
            case XMLStreamConstants.END_ELEMENT:
            case XMLStreamConstants.END_DOCUMENT:
                // discard events until we encounter matching END_ELEMENT
                reader.require(XMLStreamConstants.END_ELEMENT, namespace, name);
                reader.next();
                return;
            }
        }
    }
346917
private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
        s.defaultReadObject();
        Object ex = s.readObject();
        if (ex != null)
            setExceptionalCompletion((Throwable)ex);
    }
732318
private ElementReader nextElementReaderInternal() {
        if (nextElement >= elements.size()) {
            return null;
        }
        try {
            ElementType type = elements.get(nextElement);
            switch (format) {
                case ASCII:
                    return new AsciiElementReader(
                            type,
                            getElementCount(type.getName()),
                            asciiReader);
                case BINARY_BIG_ENDIAN:
                case BINARY_LITTLE_ENDIAN:
                    return new BinaryElementReader(
                            type,
                            getElementCount(type.getName()),
                            binaryStream);
                default:
                    throw new UnsupportedOperationException("PLY format "
                            + format + " is currently not supported.");
            }
        }
        finally {
            nextElement++;
        }
    }
1232344
@SuppressWarnings("unchecked")
    private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
        // Read in any hidden serialization magic
        s.defaultReadObject();

        // Read in size
        int size = s.readInt();

        // Read in all elements in the proper order.
        for (int i = 0; i < size; i++)
            linkLast((E)s.readObject());
    }

    /**
     * Creates a <em><a href="Spliterator.html#binding">late-binding</a></em>
     * and <em>fail-fast</em> {@link Spliterator} over the elements in this
     * list.
     *
     * <p>The {@code Spliterator} reports {@link Spliterator#SIZED} and
     * {@link Spliterator#ORDERED}.  Overriding implementations should document
     * the reporting of additional characteristic values.
     *
     * @implNote
     * The {@code Spliterator} additionally reports {@link Spliterator#SUBSIZED}
     * and implements {@code trySplit} to permit limited parallelism..
     *
     * @return a {@code Spliterator} over the elements in this list
     * @since 1.8
     */
    @Override
    public Spliterator<E> spliterator() {
        return new LLSpliterator<E>(this, -1, 0);
    }

    /** A customized variant of Spliterators.IteratorSpliterator */
    static final class LLSpliterator<E> implements Spliterator<E> {
        static final int BATCH_UNIT = 1 << 10;  // batch array size increment
        static final int MAX_BATCH = 1 << 25;  // max batch array size;
        final LinkedList<E> list; // null OK unless traversed
        Node<E> current;      // current node; null until initialized
        int est;              // size estimate; -1 until first needed
        int expectedModCount; // initialized when est set
        int batch;            // batch size for splits

        LLSpliterator(LinkedList<E> list, int est, int expectedModCount) {
            this.list = list;
            this.est = est;
            this.expectedModCount = expectedModCount;
        }

        final int getEst() {
            int s; // force initialization
            final LinkedList<E> lst;
            if ((s = est) < 0) {
                if ((lst = list) == null)
                    s = est = 0;
                else {
                    expectedModCount = lst.modCount;
                    current = lst.first;
                    s = est = lst.size;
                }
            }
            return s;
        }

        public long estimateSize() { return (long) getEst(); }

        public Spliterator<E> trySplit() {
            Node<E> p;
            int s = getEst();
            if (s > 1 && (p = current) != null) {
                int n = batch + BATCH_UNIT;
                if (n > s)
                    n = s;
                if (n > MAX_BATCH)
                    n = MAX_BATCH;
                Object[] a = new Object[n];
                int j = 0;
                do { a[j++] = p.item; } while ((p = p.next) != null && j < n);
                current = p;
                batch = j;
                est = s - j;
                return Spliterators.spliterator(a, 0, j, Spliterator.ORDERED);
            }
            return null;
        }

        public void forEachRemaining(Consumer<? super E> action) {
            Node<E> p; int n;
            if (action == null) throw new NullPointerException();
            if ((n = getEst()) > 0 && (p = current) != null) {
                current = null;
                est = 0;
                do {
                    E e = p.item;
                    p = p.next;
                    action.accept(e);
                } while (p != null && --n > 0);
            }
            if (list.modCount != expectedModCount)
                throw new ConcurrentModificationException();
        }

        public boolean tryAdvance(Consumer<? super E> action) {
            Node<E> p;
            if (action == null) throw new NullPointerException();
            if (getEst() > 0 && (p = current) != null) {
                --est;
                E e = p.item;
                current = p.next;
                action.accept(e);
                if (list.modCount != expectedModCount)
                    throw new ConcurrentModificationException();
                return true;
            }
            return false;
        }

        public int characteristics() {
            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
        }
    }

    // For J2ObjC: Calling clear() avoids a deep stack of dealloc calls that occurs when each node
    // released its successor in a recursive fashion.
    protected void finalize() {
      clear();
    }

    /*-[
    - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
                                      objects:(__unsafe_unretained id *)stackbuf
                                        count:(NSUInteger)len {
      __unsafe_unretained JavaUtilLinkedList_Node *link;
      if (state->state == 0) {
        state->state = 1;
        state->mutationsPtr = (unsigned long *) &modCount_;
        link = first_;
      } else {
        link = (ARCBRIDGE id) (void *) state->extra[0];
      }
      state->itemsPtr = stackbuf;
      NSUInteger objCount = 0;
      while (link && objCount < len) {
        *stackbuf++ = link->item_;
        objCount++;
        link = link->next_;
      }
      state->extra[0] = (unsigned long) link;
      return objCount;
    }
    ]-*/
}
206151
private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
        elementData = EMPTY_ELEMENTDATA;

        // Read in size, and any hidden stuff
        s.defaultReadObject();

        // Read in capacity
        s.readInt(); // ignored

        if (size > 0) {
            // be like clone(), allocate array based upon size not capacity
            ensureCapacityInternal(size);

            Object[] a = elementData;
            // Read in all elements in the proper order.
            for (int i=0; i<size; i++) {
                a[i] = s.readObject();
            }
        }
    }
939869
public void readObject (ObjectInputStream in)
        throws IOException, ClassNotFoundException
    {
        if (!classDefinesElementType()) {
            @SuppressWarnings("unchecked") Class<E> elementType =
                (Class<E>)Class.forName(in.readUTF());
            _elementType = elementType;

        } else if (_elementType == null) {
            throw new RuntimeException("No element type defined in constructor.");
        }
        initContents();
        in.read(_contents);

        // count set bits to initialize size
        for (byte b : _contents) {
            _size += Integer.bitCount(b & 0xFF);
        }
    }
476682
public void parseStream (InputStream stream)
        throws IOException
    {
        try {
            // read the XML input stream and construct the scene object
            _chars = new StringBuilder();
            XMLUtil.parse(this, stream);

        } catch (ParserConfigurationException pce) {
            throw (IOException) new IOException().initCause(pce);

        } catch (SAXException saxe) {
            throw (IOException) new IOException().initCause(saxe);
        }
    }
1352891
public TLVElement readElement() throws IOException, TLVParserException {
        TlvHeader header = readHeader();
        TLVElement element = new TLVElement(header.tlv16, header.nonCritical, header.forwarded, header.type);
        int count = countNestedTlvElements(header);
        if (count > 0) {
            readNestedElements(element, count);
        } else {
            element.setContent(readTlvContent(header));
        }
        return element;
    }
958314
@Override
  public Result<MZXMLIndexElement> buildIndex(final IndexBuilder.Info info) throws Exception {
    Result<MZXMLIndexElement> result = new IndexBuilder.Result<>(info);

    int numOpeningScanTagsFound = 0;
    vars.reset();

    XMLStreamReaderImpl reader = (pool == null) ? new XMLStreamReaderImpl() : pool.borrowObject();
    try {
      reader.setInput(info.is, StandardCharsets.UTF_8.name());
      LogHelper.setJavolutionLogLevelFatal();

      final XMLStreamReaderImpl.LocationImpl location = reader.getLocation();
      int eventType = XMLStreamConstants.END_DOCUMENT;
      CharArray localName, attr;
      Attributes attrs;
      do {
        // Read the next XML element
        try {
          eventType = reader.next();
        } catch (XMLStreamException e) {

          if (e instanceof XMLUnexpectedEndTagException) {
            // it's ok to have unexpected closing tags
            eventType = reader.getEventType();
          } else if (e instanceof XMLUnexpectedEndOfDocumentException) {
            // as we're reading arbitrary chunks of file, we will almost always finish parsing by hitting this condition
            break;
          } else {
            throw new FileParsingException(e);
          }
        }

        // Process the read event
        switch (eventType) {

          case XMLStreamConstants.START_ELEMENT:
            localName = reader.getLocalName();
            attrs = reader.getAttributes();

            if (localName.contentEquals(MZXMLMultiSpectraParser.TAG.SCAN.name)) {
              if (vars.offsetLo != null) {
                // this means we've encountered nested Spectrum tags
                long lastStartTagPos = location.getLastStartTagPos();
                vars.length = (int) (vars.offsetLo - lastStartTagPos);
                addAndFlush(result, info.offsetInFile);
              }

              //tagScanStart(reader);
              vars.offsetLo = location.getLastStartTagPos();
              try {
                vars.scanNumRaw = attrs.getValue(MZXMLMultiSpectraParser.ATTR.SCAN_NUM.name)
                    .toInt();
              } catch (NumberFormatException e) {
                throw new FileParsingException("Malformed scan number while building index", e);
              }

            }
            break;

          case XMLStreamConstants.CHARACTERS:
            break;

          case XMLStreamConstants.END_ELEMENT:
            localName = reader.getLocalName();

            if (localName.contentEquals(MZXMLMultiSpectraParser.TAG.SCAN.name)) {
              vars.offsetHi = location.getTotalCharsRead();
              addAndFlush(result, info.offsetInFile);
            }

            break;
        }
      } while (eventType != XMLStreamConstants.END_DOCUMENT);

    } finally {
      addAndFlush(result, info.offsetInFile);

      // we need to return the reaer to the pool, if we borrowed it from there
      if (pool != null && reader != null) {
        pool.returnObject(reader);
      }
    }

    return result;
  }
160108
public String readText() throws XMLStreamException {
        if (isInsideResponseHeader()) {
            return getHeader(currentHeader);
        }
        if (currentEvent.isAttribute()) {
            Attribute attribute = (Attribute)currentEvent;
            return attribute.getValue();
        }

        StringBuilder sb = new StringBuilder();
        while (true) {
            XMLEvent event = eventReader.peek();
            if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
                eventReader.nextEvent();
                sb.append(event.asCharacters().getData());
            } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
                return sb.toString();
            } else {
                throw new RuntimeException("Encountered unexpected event: " + event.toString());
            }
        }
    }
135824
public static Element parse(InputStream xmlStream, DocumentBuilder builder) throws IOException
   {
      try
      {
         Document doc;
         synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder
         {
            doc = builder.parse(xmlStream);
         }
         return doc.getDocumentElement();
      }
      catch (SAXException se)
      {
         throw new IOException(se.toString());
      }
      finally
      {
         xmlStream.close();
      }
   }
384054
private Object parseXmlElement(Element element) {
        if(element.getFirstChild() instanceof Text) {
            Text text = (Text) element.getFirstChild();
            return text.getData();
        }
        return element;
    }
141022
private void readHeader(final PushbackInputStream stream)
            throws IOException {
        UnbufferedASCIIReader hdrReader = new UnbufferedASCIIReader(stream);
        String magic = hdrReader.readLine();
        if (!"ply".equals(magic)) {
            throw new IOException("Invalid PLY file: does not start "
                    + "with 'ply'.");
        }

        format = null;
        ElementType.HeaderEntry currentElement = null;
        List<Property> currentElementProperties = null;
        elements = new ArrayList<ElementType>();
        elementCounts = new HashMap<String, Integer>();
        rawHeaders = new ArrayList<String>();

        for (String line = hdrReader.readLine(); true;
                line = hdrReader.readLine()) {
            if (line == null) {
                throw new IOException("Unexpected end of file while "
                        + "reading the header.");
            }
            line = line.trim();
            if (line.isEmpty()) {
                continue;
            }
            rawHeaders.add(line);
            if (line.startsWith("format ")) {
                if (format != null) {
                    throw new IOException("Multiple format definitions.");
                }
                format = Format.parse(line);
            } else if (line.startsWith("element ")) {
                if (currentElement != null) {
                    // finish the last element
                    ElementType element = new ElementType(
                            currentElement.getName(),
                            currentElementProperties);
                    elements.add(element);
                    elementCounts.put(currentElement.getName(),
                            currentElement.getCount());
                    currentElement = null;
                    currentElementProperties = null;
                }
                currentElement = ElementType.parse(line);
                currentElementProperties = new ArrayList<Property>();
            } else if (line.startsWith("property ")) {
                if (currentElement == null) {
                    throw new IOException("Property without element found.");
                }
                Property property = Property.parse(line);
                currentElementProperties.add(property);
            } else if (line.startsWith("end_header")) {
                break;
            }
        }

        if (currentElement != null) {
            // finish the last element
            ElementType element = new ElementType(currentElement.getName(),
                    currentElementProperties);
            elements.add(element);
            elementCounts.put(currentElement.getName(),
                    currentElement.getCount());
            currentElement = null;
            currentElementProperties = null;
        }
        elements = Collections.unmodifiableList(elements);

        if (format == null) {
            throw new IOException("Missing format header entry.");
        }

        switch (format) {
            case ASCII:
                this.asciiReader = new BufferedReader(new InputStreamReader(
                        stream, Charset.forName("US-ASCII")));
                this.binaryStream = null;
                break;
            case BINARY_BIG_ENDIAN:
                this.asciiReader = null;
                this.binaryStream = new BinaryPlyInputStream(
                        Channels.newChannel(stream), ByteOrder.BIG_ENDIAN);
                break;
            case BINARY_LITTLE_ENDIAN:
                this.asciiReader = null;
                this.binaryStream = new BinaryPlyInputStream(
                        Channels.newChannel(stream), ByteOrder.LITTLE_ENDIAN);
                break;
            default:
                throw new IOException("Unsupported format: " + format);
        }
    }