Skip to content
Snippets Groups Projects

refacto: move file quality control into a service implementing an interface

Merged Nicolas.Rod requested to merge rodn-file-metadata-interface into master
2 unresolved threads
@@ -18,31 +18,19 @@ public class PdfBoxMetadataExtractor implements FileMetadataExtractor {
@Override
public boolean isPasswordProtected(DocumentFile pdfDocumentFile) throws IOException {
PDDocument doc = null;
try {
doc = PDDocument.load(new File(pdfDocumentFile.getFinalData()));
try (PDDocument doc = PDDocument.load(new File(pdfDocumentFile.getFinalData()))) {
return false;
} catch (InvalidPasswordException invalidPasswordException) {
return true;
} finally {
if (doc != null) {
doc.close();
}
}
}
@Override
public String getText(DocumentFile pdfDocumentFile) throws IOException {
if (!this.isPasswordProtected(pdfDocumentFile)) {
PDDocument doc = null;
try {
doc = PDDocument.load(new File(pdfDocumentFile.getFinalData()));
try (PDDocument doc = PDDocument.load(new File(pdfDocumentFile.getFinalData()))) {
String text = new PDFTextStripper().getText(doc);
return text;
} finally {
if (doc != null) {
doc.close();
}
}
} else {
return null;
Loading