I’m using wicket to have large (~2Gb+) zip files submitted to a web application, to process the zip file I’m using the java.util.zip.* classes and I need to be able to read random entries from the zip file. So my code is something like this:
class MyForm extends Form {
private FileUploadField fileField;
MyForm(String id) {
super(id);
fileField = new FileUploadField("upload");
add(fileField);
}
@Override
protected void onSubmit() {
FileUpload fileUpload = fileField.getFileUpload();
File file = fileUpload.writeToTempFile();
ZipFile zipFile = new ZipFile(file);
// Do more stuff
}
}
As the upload is large wicket puts it in a temp file when parsing the request, but then writeToTempFile() copies it into another temp file, so I now have two copies of the file on disk. This wastes disk space, disk IO and increased the request processing time.
I can’t use ZipFileInputStream as I need to access the files in a random order. Is there a way to stop wicket duplicating the file on disk?
Yes, but it’s not a nice way.
You can subclass
FileUploadFieldand override thegetFileUpload()method with a copy that exposes the underlyingFileItem.Or, another way is to create a new method in your
FileUploadFieldsubclass just to return theFileItem: