/** * Create a temporary File from a given entry of a given ZipFile. You must * delete the temp file after using it. * * @param zipFile * the Zipped file to search in, must be non null * @param entryName * the name of an entry in the Zip file, must be non null and non * empty * @throws PetalsException * if entry can't be found or if an error occured during zip * reading * @throws IOException * @return a temp File read from the Zip entry, not <code>null</code>. */ public static File getEntryAsTemp(ZipFile zipFile, String entryName) throws PetalsException, IOException { File tempFile = null; InputStream zipStream = null; ZipEntry theEntry = getZipEntry(zipFile, entryName); zipStream = zipFile.getInputStream(theEntry); tempFile = File.createTempFile("petals-", null); NioUtil.copyStreamToFile(zipStream, tempFile); return tempFile; }
@SuppressWarnings("deprecation") public File explodeSUIntoSAInstallDirectory(String serviceUnitId, URL suZipLocation, String serviceAssemblyId) throws IOException { File installationRoot = this.createSUInstallDirectory(serviceUnitId, serviceAssemblyId); try { File zipArchive = new File(URLDecoder.decode(suZipLocation.getPath())); ZipUtil.unzipArchive(zipArchive, installationRoot); } catch (IOException e) { try { FileUtils.forceDelete(installationRoot); } catch (IOException e1) { // Nothing to do, just log this.log.warning("Failed to clean a failed installation", e); } throw e; } return installationRoot; }
tmpJBIFile = ZipUtil.getEntryAsTemp(zipArchive, JBI_DESCRIPTOR_RESOURCE);
unzipEntry(zip, entry, file);
@SuppressWarnings("deprecation") private File explodeEntityPackage(URL archiveUrl) throws PetalsException { File zipFile = new File(URLDecoder.decode(archiveUrl.getPath())); File destFile = new File(this.getWorkDirectory(), zipFile.getName() + "-" + uniqueIdSuffix.incrementAndGet()); try { destFile.mkdir(); ZipUtil.unzipArchive(zipFile, destFile); } catch (IOException e) { try { FileUtils.forceDelete(destFile); } catch (IOException e1) { // Nothing to do, just log this.log.warning("Failed to delete the temporary directory '" + destFile.getAbsolutePath() + "'", e); } throw new PetalsException(e); } return destFile; }