private StreamingOutput produceOutput(final InputStream is, Metadata metadata, final MultivaluedMap<String, String> httpHeaders, final UriInfo info, final String format) {
        final Parser parser = createParser();
        final ParseContext context = new ParseContext();

        fillMetadata(parser, metadata, httpHeaders);
        fillParseContext(httpHeaders, metadata, context);


        logRequest(LOG, "/tika", metadata);

        return outputStream -> {
            Writer writer = new OutputStreamWriter(outputStream, UTF_8);
            ContentHandler content;

            try {
                SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
                TransformerHandler handler = factory.newTransformerHandler();
                handler
                        .getTransformer()
                        .setOutputProperty(OutputKeys.METHOD, format);
                handler
                        .getTransformer()
                        .setOutputProperty(OutputKeys.INDENT, "yes");
                handler
                        .getTransformer()
                        .setOutputProperty(OutputKeys.ENCODING, UTF_8.name());
                handler
                        .getTransformer()
                        .setOutputProperty(OutputKeys.VERSION, "1.1");
                handler.setResult(new StreamResult(writer));
                content = new ExpandedTitleContentHandler(handler);
            } catch (TransformerConfigurationException e) {
                throw new WebApplicationException(e);
            }

            parse(parser, LOG, info.getPath(), is, content, metadata, context);
        };
    }
Use this to call a parser and unify exception handling.
NOTE: This call to parse closes the InputStream. DO NOT surround
the call in an auto-close block.

@param parser       parser to use
@param logger       logger to use
@param path         file path
@param inputStream  inputStream (which is closed by this call!)
@param handler      handler to use
@param metadata     metadata
@param parseContext parse context
@throws IOException wrapper for all exceptions
tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaResource.java