Source:
<code>public ZipVaultPackage upload(InputStream in, boolean replace) throws IOException, PackageExistsException { MemoryArchive archive = new MemoryArchive(true); File tempFile = File.createTempFile("upload", ".zip"); InputStreamPump pump = new InputStreamPump(in , archive); try { try { FileUtils.copyInputStreamToFile(pump, tempFile); } catch (Exception e) { String msg = "Stream could be read successfully."; log.error(msg); throw new IOException(msg, e); } if (archive.getJcrRoot() == null) { String msg = "Stream is not a content package. Missing 'jcr_root'."; log.error(msg); throw new IOException(msg); } final MetaInf inf = archive.getMetaInf(); PackagePropertiesImpl props = new PackagePropertiesImpl() { @Override protected Properties getPropertiesMap() { return inf.getProperties(); } }; PackageId pid = props.getId(); <START> if (pid == null) { <END> pid = createRandomPid(); } if (!pid.isValid()) { throw new IllegalArgumentException("Unable to create package. Illegal package name."); } File oldPkgFile = getPackageFile(pid); String path = oldPkgFile.exists() ? oldPkgFile.getAbsolutePath() : getInstallationPath(pid); String name = Text.getName(path); if (oldPkgFile.exists()) { if (replace) { oldPkgFile.delete(); } else { throw new PackageExistsException("Package already exists: " + pid).setId(pid); } } ZipVaultPackage pkg = new ZipVaultPackage(archive, true); File pkgFile = getPackageFile(pid); FileUtils.moveFile(tempFile, pkgFile); dispatch(PackageEvent.Type.UPLOAD, pid, null); return pkg; } finally { pump.close(); } }</code><technical_language>sure.. I throw IOException (incomplete package metadata) longer support it</technical_language>

Target:
public ZipVaultPackage upload(InputStream in, boolean replace) throws IOException, PackageExistsException { MemoryArchive archive = new MemoryArchive(false); File tempFile = File.createTempFile("upload", ".zip"); try (InputStreamPump pump = new InputStreamPump(in, archive)) { try { FileUtils.copyInputStreamToFile(pump, tempFile); } catch (Exception e) { String msg = "Stream could be read successfully."; log.error(msg); throw new IOException(msg, e); } if (archive.getJcrRoot() == null) { String msg = "Stream is not a content package. Missing 'jcr_root'."; log.error(msg); throw new IOException(msg); } final MetaInf inf = archive.getMetaInf(); PackagePropertiesImpl props = new PackagePropertiesImpl() { @Override protected Properties getPropertiesMap() { return inf.getProperties(); } }; PackageId pid = props.getId(); if (pid == null) { throw new IllegalArgumentException("Unable to create package. No package pid set."); } if (!pid.isValid()) { throw new IllegalArgumentException("Unable to create package. Illegal package name."); } File oldPkgFile = getPackageFile(pid); FSInstallState state = getInstallState(pid); if (oldPkgFile != null && oldPkgFile.exists()) { if (replace && !state.isExternal()) { oldPkgFile.delete(); } else { throw new PackageExistsException("Package already exists: " + pid).setId(pid); } } ZipVaultPackage pkg = new ZipVaultPackage(archive, true); registerSubPackages(pkg, replace); File pkgFile = buildPackageFile(pid); FileUtils.moveFile(tempFile, pkgFile); dispatch(Type.UPLOAD, pid, null); return pkg; } }