indexer.index(Collections.singleton(newFile.getCanonicalFile()), newIndexBuffer, null);
// Merge into main index
File tempIndex = File.createTempFile("repository", ".xml");
FileOutputStream tempIndexOutput = new FileOutputStream(tempIndex);
MergeContentFilter merger = new MergeContentFilter();
XMLReader reader = SAXUtil.buildPipeline(new StreamResult(tempIndexOutput), new UniqueResourceFilter(), merger);
try {
// Parse the newly generated index
reader.parse(new InputSource(new ByteArrayInputStream(newIndexBuffer.toByteArray())));
// Parse the existing index (which may be empty/missing)
try {
reader.parse(new InputSource(new FileInputStream(localIndex)));
} catch (Exception e) {
reporter.warning("Existing local index is invalid or missing, overwriting (%s).", localIndex.getAbsolutePath());
}
merger.closeRootAndDocument();
} finally {
tempIndexOutput.flush();
tempIndexOutput.close();
}
IO.copy(tempIndex, localIndex);