{
filesClusteredTotal++;
final Map<String, Object> attributes = Maps.newHashMap();
attributes.put("XmlDocumentSource.xml", new FileResource(fileOrDirectory));
final ProcessingResult result = controller.process(attributes,
XmlDocumentSource.class.getName(), algorithm);
// Stick to UTF-8 encoding on the output.
final String outputFileName =
Format.JSON.equals(outputFormat) && fileName.endsWith(".xml")
? fileName.substring(0, fileName .length() - 4) + ".json" : fileName;
final OutputStream stream = new FileOutputStream(
new File(currentOutputDir, outputFileName));
try
{
if (Format.JSON.equals(outputFormat))
{
Writer w = new OutputStreamWriter(stream, "UTF-8");
result.serializeJson(w, null, outputDocuments, true, outputAttributes);
w.flush();
}
else
{
result.serialize(stream, outputDocuments, true, outputAttributes);
}
}
finally
{
CloseableUtils.close(stream);
}
log.info("Clustering " + fileOrDirectory.getAbsolutePath() + " ["
+ result.getAttribute(AttributeNames.PROCESSING_TIME_TOTAL) + "ms]");
}
}