class StreamSourceEntityProvider implements EntityProvider<StreamSource> {

    @Override
    public void writeTo(StreamSource streamSource,
                        Class<?> type,
                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream) throws IOException {
        StreamResult streamResult = new StreamResult(entityStream);
        try {
            TransformerFactory factory = createFeaturedTransformerFactory();
            factory.newTransformer().transform(streamSource, streamResult);
        } catch (TransformerException | TransformerFactoryConfigurationError e) {
            throw new IOException(String.format("Can't write to output stream, %s", e));
        }
    }

}