dan-s1 commented on code in PR #9874:
URL: https://github.com/apache/nifi/pull/9874#discussion_r2052566486
##########
nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/RowIterator.java:
##########
@@ -129,4 +151,37 @@ private boolean hasExhaustedRows() {
}
return exhausted;
}
+
+ private boolean isXSSFExcelFile(InputStream in, final String password) {
+ final FileMagic fileType;
+ try {
+ fileType = FileMagic.valueOf(in);
+ } catch (final IOException e) {
+ throw new ProcessException("Failed to determine file type", e);
+ }
+
+ if (fileType == FileMagic.OOXML) {
+ // Unencrypted XLSX file
+ return true;
+ }
+ if (fileType != FileMagic.OLE2) {
+ // Not an Excel file
+ return false;
+ }
+ if (password == null) {
+ // If there is no password on the OLE2 file, then it's an XLS
file. Otherwise, the type must be further
+ // investigated.
+ return false;
+ }
+
+ DirectoryNode root;
+ try {
+ root = new POIFSFileSystem(new
NonCloseableInputStream(in)).getRoot();
Review Comment:
In addition I think the creation of `POIFSFileSystem` and the assignment to
`root` should be done on separate lines. In addition, the return statement
should be all done in the try block as if the instantiation of
`POIFSFileSystem` throws an IOException the return statement is never reached.
```suggestion
try {
final POIFSFileSystem poifsFileSystem = new POIFSFileSystem(new
NonCloseableInputStream(in)).getRoot();
final DirectoryNode root = poifsFileSystem.getRoot() ;
return root.hasEntryCaseInsensitive(DEFAULT_POIFS_ENTRY) ||
root.hasEntryCaseInsensitive(OOXML_PACKAGE);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]