// Create the result.
final OutputStream actualOutput;
if (stepType.isLast() || logger.isDebugEnabled()) {
// Caching a copy of the marshalled data for validation or dumping
actualOutput = new CachingOutputStream(output);
} else {
actualOutput = output;
}
Result outputResult = new StreamResult(actualOutput);
// Do the transform.
Transformer transform = templates.newTransformer();
transform.setErrorListener(new LoggingListener());
transform.transform(inputSource, outputResult);
// Dump the output of this migrator for debugging
if (logger.isDebugEnabled()) {
logger.debug("Output from migrator");
CachingOutputStream cachedOutput =
((CachingOutputStream) actualOutput);
InputStream is = cachedOutput.getCacheInputStream();
dumpStream(is);
}
if (stepType.isLast()) {
// Do validation of the output.
CachingOutputStream cachedOutput =
((CachingOutputStream) actualOutput);
InputStream reader = cachedOutput.getCacheInputStream();
ContentInput content = new BinaryContentInput(reader);
try {
outputSchemaValidator.validate(content);
} catch (SAXException e) {