How to create a ZIP file WITHOUT using a temp file, but fully using our File storage?

Hi all!   I have a Java action to create a ZIP which works really fine.   But there is 1 limitation, I have to create a temp file to prepare the ZIP before saving it in my regular file storage. And when I create a big zip (>4GB) there is not enough disk space (in the temp folder) and my application crashes.   Here my source code for the Java action. Is there any way to initialize a ZipOutputStream without creating a temp file, but using a file from our file storage?   public IMendixObject executeAction() throws Exception { // BEGIN USER CODE File tempZipFile = File.createTempFile("zipfile", "temp"); ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(tempZipFile)); InputStream inputStream = Core.getFileDocumentContent(getContext(), fileToZip); String fileName = fileToZip.getValue(getContext(), "Name"); if (fileName == null || fileName.isEmpty()) { fileName = "document.pdf"; } ZipEntry zipEntry = new ZipEntry(fileName); zipOut.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = >= 0) { zipOut.write(bytes, 0, length); } inputStream.close(); zipOut.close(); InputStream zipInputStream = new FileInputStream(tempZipFile); IMendixObject finalZipDoc = Core.instantiate(getContext(), finalZip); Core.storeFileDocumentContent(getContext(), finalZipDoc, zipInputStream); zipInputStream.close(); tempZipFile.delete(); return finalZipDoc; // END USER CODE }  
2 answers

Hi Claire,


Have you checked this limitation of the original .ZIP file format? I suspect that the problem may be related to this:


"The original .ZIP format had a 4 GB (232 bytes) limit on various things (uncompressed size of a file, compressed size of a file, and total size of the archive)"


I suggest that you try using another library for compressing the files to see if that fixes your issue. You could probably use this:

Apache Commons Compress (documentation)

Maven Repository


I hope that helps you solve your issue, best regards!


Hi Oswaldo,


Thanks for your answer, but the issue is not a ZIP limitation.


I use Apache commons compress library, version 1.19, and in this version of the library, using ZipArchiveInputStream the archive size is unlimited.


Moreover, the error sent back by my Java action is "not enough disk space", it's not a Zip error exception.