class UnopenedElementClosingEventWriter extends AbstractEventWriterWrapper {

	private final LinkedList<QName> unopenedElements;

	private final Writer ioWriter;

	public UnopenedElementClosingEventWriter(XMLEventWriter wrappedEventWriter, Writer ioWriter,
			List<QName> unopenedElements) {
		super(wrappedEventWriter);
		this.unopenedElements = new LinkedList<>(unopenedElements);
		this.ioWriter = ioWriter;
	}

	@Override
	public void add(XMLEvent event) throws XMLStreamException {<FILL_FUNCTION_BODY>}

	private boolean isUnopenedElementCloseEvent(XMLEvent event) {
		if (unopenedElements.isEmpty()) {
			return false;
		}
		else if (!event.isEndElement()) {
			return false;
		}
		else {
			return unopenedElements.getLast().equals(event.asEndElement().getName());
		}
	}

}

		if (isUnopenedElementCloseEvent(event)) {
			QName element = unopenedElements.removeLast();
			String nsPrefix = !StringUtils.hasText(element.getPrefix()) ? "" : element.getPrefix() + ":";
			try {
				super.flush();
				ioWriter.write("</" + nsPrefix + element.getLocalPart() + ">");
				ioWriter.flush();
			}
			catch (IOException ioe) {
				throw new XMLStreamException("Unable to close tag: " + element, ioe);
			}
		}
		else {
			super.add(event);
		}
	
<methods>public void <init>(javax.xml.stream.XMLEventWriter) ,public void add(javax.xml.stream.events.XMLEvent) throws javax.xml.stream.XMLStreamException,public void add(javax.xml.stream.XMLEventReader) throws javax.xml.stream.XMLStreamException,public void close() throws javax.xml.stream.XMLStreamException,public void flush() throws javax.xml.stream.XMLStreamException,public javax.xml.namespace.NamespaceContext getNamespaceContext() ,public java.lang.String getPrefix(java.lang.String) throws javax.xml.stream.XMLStreamException,public void setDefaultNamespace(java.lang.String) throws javax.xml.stream.XMLStreamException,public void setNamespaceContext(javax.xml.namespace.NamespaceContext) throws javax.xml.stream.XMLStreamException,public void setPrefix(java.lang.String, java.lang.String) throws javax.xml.stream.XMLStreamException<variables>protected javax.xml.stream.XMLEventWriter wrappedEventWriter