The following code is a test program that creates an xlsx blob using the Apache POI and decompresses the blob (xlsx is in zip format) to check some values. The code is based on stack overflow questions, but I was not able to figure out how to work properly. The requirement for this is that the file system should not be affected, so we resort to threads.
The problem is that the line
int size = (int) entry.getSize();
always produces -1. However see comments before
zipInput.closeEntry();
for an option that is included in the program, but it seems incorrect.
We do not want to use the POI to read the xlsx file because we are testing a problem where the POI does not seem to be working with Apache Struts, and we want to eliminate the case when we use the POI regardless of Struts is the culprit. Once this test passes, if the problem Struts reports remain, we know that we are looking at how we use the POI.
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class CreateWorkbook { public static void main(String[] args) throws IOException {
source share