I've noticed that the workbook creation statement for xlsx files with Apache POI v3.10 e.g. `
Workbook wb = WorkbookFactory.create(inputStream)
or
Workbook wb = new XSSFWorkbook(inputStream)
...is taking a long time (~30 seconds) and the file only has 72 rows with 10 columns (365KB).
It's not a problem, but it just seems a bit excessive. I'm wondering if I'm doing anything wrong or not doing something I should be doing. Instantiation of an xls file with the same data (but only 25KB) only takes 1 or 2 seconds. If this is normal, then could someone just let me know.
Edit:
This is the workbook creation code I'm using:
LOG.info("Loading Excel Workbook...");
Workbook workbook;
try {
workbook = WorkbookFactory.create(dataStream);
} catch (InvalidFormatException e) {
throw new IOException("Invalid file format ==> " + e.getMessage());
}
LOG.info("Workbook loaded.");
Just to be clear, dataStream
is an InputStream
. The 30 second delay occurs between the first and second log statements. As I said previously, I've tried replacing the factory with new XSSFWorkbook(dataStream)
but the delay remains.
Edit-2:
I ran a standalone test which does nothing except the workbook initialization using 1) a File
, and also 2) an InputStream
where the source is the xlsx file I've been having trouble with. They both completed in ~2 seconds.
I should have added some background earlier. I'm using the Google App Engine. The input stream that I'm giving to POI is retrieved from a file upload to the server. App Engine doesn't support Servlet 3.0 (for handling file uploads) so I have to use Apache Commons FileUpload lib to retrieve the file data. Ultimately, the data I get is an InputStream
retrieved from FileItemStream#openStream(). This is what I supply to POI.
So, I don't know if this is a problem with the App Engine, or if POI doesn't like the flavor of the InputStream that FileItemStream
is returning. Incidentally, I cannot try the initialization with a File
instead of a InputStream
because App Engine doesn't allow writes to the file system.