public IndexDocument getIndexedDocument(File2Index fileData) throws SolrException {
COSDocument cosDoc = null;
try {
PDFParser parser = new PDFParser(new ByteArrayInputStream(fileData.data));
parser.parse();
cosDoc = parser.getDocument();
PDFTextStripper stripper = new PDFTextStripper();
String docText = stripper.getText(new PDDocument(cosDoc));
return new IndexDocument(fileData.path, docText, null);
} catch (IOException e) {
String msg = "Failed to write to the index";
log.error(msg, e);
throw new SolrException(ErrorCode.SERVER_ERROR, msg);
} finally {
if (cosDoc != null) {
try {
cosDoc.close();
} catch (IOException e) {
log.error("Failed to close pdf doc stream ",e);
}
}
}
}