Q:

Wicket FileUploadField and large zip uploads

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?

A:

Yes, but it's not a nice way.
You can subclass FileUploadField and override the getFileUpload() method with a copy that exposes the underlying FileItem.
Or, another way is to create a new method in your FileUploadField subclass just to return the FileItem:
public FileItem getFileItem() {
    return ((IMultipartWebRequest)getRequest()).getFile(getInputName());
}

