use of org.apereo.portal.xml.stream.ChunkingEventReader in project uPortal by Jasig.
the class StAXSerializingComponent method getEventReader.
@Override
public PipelineEventReader<CharacterEventReader, CharacterEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = this.wrappedComponent.getEventReader(request, response);
//Writer shared by the ChunkingEventReader and the StAX Serializer
final StringWriter writer = new StringWriter();
final XMLOutputFactory outputFactory = this.xmlUtilities.getHtmlOutputFactory();
final XMLEventWriter xmlEventWriter;
try {
xmlEventWriter = outputFactory.createXMLEventWriter(writer);
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLEventWriter", e);
}
//Add the chunking wrapper to the XMLEventReader
final XMLEventReader xmlEventReader = eventReader.getEventReader();
final ChunkingEventReader chunkingEventReader = new ChunkingEventReader(request, this.chunkingElements, this.chunkingPatternEventSources, this.chunkingPatterns, xmlEventReader, xmlEventWriter, writer);
try {
xmlEventWriter.add(chunkingEventReader);
xmlEventWriter.flush();
xmlEventWriter.close();
chunkingEventReader.close();
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to write events to Writer", e);
}
//Return the chunked data
final List<CharacterEvent> characterEvents = chunkingEventReader.getCharacterEvents();
final CharacterEventBufferReader characterEventReader = new CharacterEventBufferReader(characterEvents.listIterator());
final Map<String, String> outputProperties = eventReader.getOutputProperties();
return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(characterEventReader, outputProperties);
}
Aggregations