package com.jasmine.javax.xmleventreader;

import java.io.ByteArrayOutputStream;
import java.util.List;

import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class XMLEventsToByteArray implements ApplicationContextAware{

	private ApplicationContext context;
	
	public void setApplicationContext(ApplicationContext context)
			throws BeansException {
		this.context=context;
	}	
	public byte[] convert(List<XMLEvent> xmlEvents) throws XMLStreamException{
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		XMLEventWriter xmlEventWriter=context.getBean(XMLEventWriter.class, outputStream);
		for(XMLEvent xmlEvent: xmlEvents)
			xmlEventWriter.add(xmlEvent);
		xmlEventWriter.close();
		return outputStream.toByteArray();
	}

}
@@ -793,16 +793,33 @@
 tWriter=
+(XMLEventWriter) 
 context.
@@ -826,19 +826,20 @@
 getBean(
-XML
+%22xml
 EventWri
@@ -845,14 +845,9 @@
 iter
-.class
+%22
 , ou
@@ -996,8 +996,9 @@
 );%0A%09%7D%0A%0A%7D
+%0A

Update XMLEventsToByteArray.java