Switch from commons-fileupload to commons-fileupload-jakarta-servlet6

I need to change my fileupload-integration to the jakarta6-version. The old code is
        resp.setHeader("Transfer-Encoding", "chunked");
        byte timeout = parseTimeoutParameter(req);
        int port = parsePortParameter(req);
        long expLen = Long.valueOf(req.getHeader(HttpHeaders.CONTENT_LENGTH));
        ServletFileUpload upload = new ServletFileUpload();
        ServletOutputStream servletOut = resp.getOutputStream();
            FileItemIterator itemIterator = upload.getItemIterator(req);
            while (itemIterator.hasNext()) {
                FileItemStream streamItem = itemIterator.next();
                if (streamItem.getFieldName().equals("ova")) {
                    String nameWithoutQuotas = streamItem.getName();
                    nameWithoutQuotas = nameWithoutQuotas.substring(0, nameWithoutQuotas.lastIndexOf('.'));
                    File tf = File.createTempFile("ova-rm", ".ova");
                    FileOutputStream fos = new FileOutputStream(tf);
                    copy(streamItem.openStream(), fos, servletOut, 1024 * 8, expLen);
                    fos.close();
                    try {
                        app.getBean(OVAImporter.class).importOVA(tf, nameWithoutQuotas, timeout, port);
                    } catch (Exception e) {
                        throw new ServletException(e);
                    }
                }
            }
        
. Using the new version I have this constructor: new JakartaServletFileUpload<FileItem<I>, FileItemFactory<I>>();. How to use the constructor properly?
Was this page helpful?