I am using the Apache POI class SXSSFWorkbook through Peoplecode to write large amounts of data to an excel file. I know very little Java but was able to put together code which produces the file using java reflection through Peoplecode. Unfortunately there is a bug in Peoplecode which makes it necessary to use reflection even when a method is not overloaded.
As an example, to execute the following java code:
SXSSFWorkbook workbook = new SXSSFWorkbook(100); /* 100 rows of accessible data */
SXSSFSheet sheet = workbook.getSheet(&name);
The equivalent in Peoplecode using java reflection is:
&_workbook = CreateJavaObject("org.apache.poi.xssf.streaming.SXSSFWorkbook", 100);
&_sheet = GetJavaClass("org.apache.poi.xssf.streaming.SXSSFSheet");
Local JavaObject &javaString = CreateJavaObject("java.lang.String", &name);
Local JavaObject &stringType = CreateJavaObject("java.lang.Class[]", &javaString.getClass());
Local JavaObject &getSheet = &_class.getDeclaredMethod("getSheet", &stringType);
Local JavaObject &args = CreateJavaObject("java.lang.Object[]", &javaString);
&_sheet = &getSheet.invoke(&_workbook, &args);
This technique works for all the methods using String, Integer, boolean as a parameter value.
Now I need to disable the Zip64 extensions by using the enum constant "Never".
Required java code:
workbook.setZip64Mode(Zip64Mode.Never);
Updated: I tried the following
&_workbook = CreateJavaObject("org.apache.poi.xssf.streaming.SXSSFWorkbook");
&_class = &_workbook.getClass();
Local JavaObject &javaString = GetJavaClass("org.apache.commons.compress.archivers.zip.Zip64Mode").valueOf("Never");
Local JavaObject &stringType = CreateJavaObject("java.lang.Class[]", GetJavaClass("org.apache.commons.compress.archivers.zip.Zip64Mode"));
Local JavaObject &setZip64Mode = &_class.getDeclaredMethod("setZip64Mode", &stringType);
Local JavaObject &args = CreateJavaObject("java.lang.Object[]", &javaString);
&setZip64Mode.invoke(&_workbook, &args);
&_class = Null;
This executes but does not change the size of the output file at all.
GetJavaClass(org.apache.commons.compress.archivers.zip.Zip64Mode).valueOf("Never"); returns a string value of "org.apache.commons.compress.archivers.zip.Zip64Mode" instead of "Never".
setZip64Mode(org.apache.commons.compress.archivers.zip.Zip64Mode zip64Mode)
What am I missing?
After a lot of research and additional information the code below is working as expected.
However, it was discovered that Peoplecode gives the same error if a java method does not exist OR if it was not called with the correct syntax (parameter type)
The code below can be used instead of the reflection code shown above:
Although the file size did not change, it was observed to not produce a zip-bomb error when opened for reading. This was the actual problem. To check whether the file could successfully be processed, Araxis-Merge was used to validate the file.
Example of Zip-Bomb error and valid file