@Override
    public void endDocument() throws SAXException {

        try {
            handler.endDocument();

            outputStream.flush();
            outputStream.close();

            if (LOGGER.isDebugEnabled()) {
                try {
                    LOGGER.debug(XMLUtil.prettyPrintXML(outputStream.toString()));
                } catch (final RuntimeException e) {
                    LOGGER.debug("Not XML");
                    LOGGER.debug(outputStream.toString());
                }
            }

        } catch (final IOException e) {
            try {
                errorListener.fatalError(new TransformerException(e.getMessage()));
            } catch (final TransformerException te) {
                LOGGER.error(MarkerFactory.getMarker("FATAL"), te.getMessage(), te);
            }
        } finally {
            super.endDocument();
        }
    }
@throws SAXException any SAX exception, possibly wrapping another exception
@see #startDocument
@see AbstractXMLFilter#endDocument()
stroom-pipeline/src/main/java/stroom/pipeline/filter/AbstractSamplingFilter.java