This is a solution that stores to Mendix filedocuments, which is often better. You can patch it to write them to the temp dir. Some snippets to put in your java action (zipfile is inputparameter. ImportFile is a filedocument specialisation)
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.IOUtils;
ZipInputStream zis = new ZipInputStream(Core.getFileDocumentContent(getContext(), zipfile.getMendixObject()));
ZipEntry ze = zis.getNextEntry();
while(ze!=null){
String filename = substringAfterLast(ze.getName(), "/");
ImportFile zipEntryDocument = new ImportFile(getContext());
// set attributes
zipEntryDocument.setName(filename);
// use intermediate memory stream because storeFileDocumentContent will close the zis stream.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(zis, baos);
Core.storeFileDocumentContent(this.getContext(), zipEntryDocument.getMendixObject(), new ByteArrayInputStream(baos.toByteArray()));
zipEntryDocument.commit();
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
Extra code
public static String substringAfterLast(String str, String separator) {
if (str.isEmpty()) {
return str;
}
if (separator.isEmpty()) {
return str;
}
int pos = str.lastIndexOf(separator);
if (pos == -1 || pos == (str.length() - separator.length())) {
return str;
}
return str.substring(pos + separator.length());
}
Edit 1: ImportFile is a specific mendix entity that inherits from filedocument. Replace it with your own entity.
Check the how-to's on how to use Java and Mendix. After that try the java.util.zip package.