public static void writeStreamContent(XMLInputFactory inputFactory, XMLStreamWriter writer, InputStream content, Map<String, String> replacementMap, LocalizationUtil localizationUtil) throws XMLStreamException {

        XMLEventReader parser = inputFactory.createXMLEventReader(content);
        StartElement startElement;
        Characters characters;
        while (parser.hasNext()) {
            XMLEvent event = parser.nextEvent();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_ELEMENT:
                    startElement = (StartElement) event;
                    writer.writeStartElement(startElement.getName().getLocalPart());
                    writeAttributes(writer, startElement.getAttributes());
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    writer.writeEndElement();
                    break;
                case XMLStreamConstants.CHARACTERS:
                    characters = (Characters) event;
                    String text = characters.getData().trim();
                    if (!text.isEmpty()) {
                        if (replacementMap != null && !replacementMap.isEmpty()) {
                            for (Map.Entry<String, String> entry : replacementMap.entrySet()) {
                                text = text.replace(entry.getKey(), entry.getValue());
                            }
                        }
                        writer.writeCharacters(localizationUtil.translate(text, 0.0));
                    }
                    break;
                default: // CDATA containing button styling is ignored intentionally
            }
        }
        parser.close();
    }